1)用户权限管理最好是细分到DB级 或 Table级,不要轻易开通全局权限;
2)用grant 和 revoke,进行用户授权和收权;
mysql> grant select on db.* to user@host identified by ‘passwd’;
mysql> revoke all on db.* from user@host;
mysql> flush privileges;
注意:对用户权限作变更后需运行flush使变更生效;
3)查看服务器运行状况的几个重要命令;
show status; 显示系统的运行状态
show variables; 显示系统运行的参数设置与环境变量
show processlist; 显示现有的访问连接;
对master slave系统还有:show master/slave status;
4)设置最大的并发响应连接数、等待响应队列的最大等待连接数(上限与具体操作系统有关)、非活动连接超时时间
最大连接数
查看:mysql> show variables like ‘max_connections’;
设置:mysql> set global max_connections = 200;
默认为100,若设置为0,则表示不作限制;
瞬时并发等待连接数
查看:mysql> show variables like ‘back_log’;
设置:mysql> set global back_log = 200;
默认为50;
非活动连接超时时间
mysql> set wait_timeout = 3600;
默认为28800,即8小时,单位秒;
5)表优化(碎片整理)
倘若一个数据量很大的表进行了大量的修改,那么可以通过命令
mysql> optimize table table_name;
来达到碎片整理的目的;
6)使用mysqlhotcopy进行数据库文件热备份
/home/mysql/bin/mysqlhotcopy db_name[./table_regex/] [new_db_name | direc tory]
示例:
/home/mysql/bin/mysqlhotcopy -u root -p ‘xxxx’ test./^tt$/ ./
注意:mysqlhotcopy是一个perl程序,需要DBI和DBD perl模块的支持
7)错误日志与binlog
错误记录日志一般是在数据目录下,如:
var/.err
binlog可以记录数据库上发生的所有操作记录,通过my.cnf中的log-bin选项来开启,如果被注释就代表关闭,binlog的内容可以通过以下命令来查看:
mysqlbinlog [options] log-files
附录 权限名称与描述列表
Privilege
Meaning
ALL [PRIVILEGES]
Sets all simple privileges except GRANT OPTION
ALTER
Allows use of ALTER TABLE
CREATE
Allows use of CREATE TABLE
CREATE TEMPORARY TABLES
Allows use of CREATE TEMPORARY TABLE
DELETE
Allows use of DELETE
DROP
Allows use of DROP TABLE
EXECUTE
Not implemented
FILE
Allows use of SELECT … INTO OUTFILE and LOAD DATA INFILE
INDEX
Allows use of CREATE INDEX and DROP INDEX
INSERT
Allows use of INSERT
LOCK TABLES
Allows use of LOCK TABLES on tables for which you have the SELECT privilege
PROCESS
Allows use of SHOW FULL PROCESSLIST
REFERENCES
Not implemented
RELOAD
Allows use of FLUSH
REPLICATION CLIENT
Allows the user to ask where slave or master servers are
REPLICATION SLAVE
Needed for replication slaves (to read binary log events from the master)
SELECT
Allows use of SELECT
SHOW DATABASES
SHOW DATABASES shows all databases
SHUTDOWN
Allows use of mysqladmin shutdown
SUPER
Allows use of CHANGE MASTER, KILL, PURGE MASTER LOGS, and SET GLOBAL statements, the mysqladmin debug command; allows you to connect (once) even if max_connections is reached
UPDATE
Allows use of UPDATE
USAGE
Synonym for “no privileges”
GRANT OPTION
Allows privileges to be granted
0 条评论。