全部博文(930)
分类: Mysql/postgreSQL
2010-06-12 18:29:16
以下的文章主要介绍的是常用技巧,我们主要是讲述七个实际应用技巧,如果你对这七个MySQL常用技巧感兴趣的话,你就可以浏览以下的文章了,望会给你带来一些帮助在此学习方面。
1)MySQL常用技巧之一,用户权限管理最好是细分到DB级 或 Table级,不要轻易开通全局权限;
2)MySQL常用技巧之二,用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)MySQL常用技巧之三,查看服务器运行状况的几个重要命令;
show status; 显示系统的运行状态
show variables; 显示系统运行的参数设置与环境变量
show processlist; 显示现有的访问连接;
对master slave系统还有:show master/slave status;
4)MySQL常用技巧之四,设置最大的并发响应连接数、等待响应队列的最大等待连接数(上限与具体操作系统有关)、非活动连接超时时间
最大连接数
查看: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常用技巧之五,表优化(碎片整理)
倘若一个数据量很大的表进行了大量的修改,那么可以通过命令
MySQL> optimize table table_name;
来达到碎片整理的目的;
6)MySQL常用技巧之六,使用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)MySQL常用技巧之七,错误日志与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
以上的相关内容就是对MySQL常用技巧的介绍,望你能有所收获。
chinaunix网友2010-06-14 17:27:50
disocuntMBT Shoes on sale! nike air max 2010 Womens MBT Chapa Shoe MBT Lami Shoe kobe shoes mbt lami shoes
chinaunix网友2010-06-14 17:27:50
disocuntMBT Shoes on sale! nike air max 2010 Womens MBT Chapa Shoe MBT Lami Shoe kobe shoes mbt lami shoes