mysq配置

mysql运维

1、mysql配置文件:/etc/my.cnf

     mysql日记文件 :安装时候配置的,可以通过ps aux|grep mysqld 查询

 

ps aux|grep mysqld 

mysql -V

查看mysql默认读取my.cnf的目录

如果没有设置使用指定目录的my.cnf,mysql启动时会读取安装目录根目录及默认目录下的my.cnf文件。查看mysql启动时读取配置文件的默认目录

命令
mysql --help|grep 'my.cnf'
输出
                      order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf

/etc/my.cnf, /etc/mysql/my.cnf, /usr/local/etc/my.cnf, ~/.my.cnf 这些就是mysql默认会搜寻my.cnf的目录,顺序排前的优先。 

 

慢查询配置:

show variables like '%slow%';

[root@localhost app]# cat /etc/my.cnf

 

[plain] view plain copy
 
  1. [mysqld]  
  2.   
  3. #----------  
  4. #其他配置参数  
  5. #-------  
  6.   
  7. #开启慢查询日志记录  
  8. slow_query_log=1  
  9.   
  10. #查询时间超过0.1秒的sql语句会被记录  
  11. long_query_time=0.1  
  12.   
  13. #记录没有使用索引的查询  
  14. log_queries_not_using_indexes=1  
  15.   
  16. #记录慢查询日志的文件地址  
  17. slow-query-log-file=/var/lib/mysql/localhost-slow.log  

 

2,在mysql控制台修改,无需重启mysqld服务

 

#开启慢查询日志记录
mysql> set global slow_query_log=on;
Query OK, 0 rows affected (0.00 sec)
#查询时间超过0.1秒的sql语句会被记录
mysql> set global long_query_time=0.1;
Query OK, 0 rows affected (0.03 sec)
#记录慢查询日志的文件地址
mysql> set global slow_query_log_file="/var/lib/mysql/localhost-slow.log";
Query OK, 0 rows affected (0.04 sec)
#记录没有使用索引的查询
mysql> set global log_queries_not_using_indexes=on;
Query OK, 0 rows affected (0.00 sec)

posted @ 2017-10-11 10:41  hechunhua  阅读(173)  评论(0编辑  收藏  举报