1 寻找mysql配置文件路径:
cd /usr/bin (到mysql执行文件路径)
./mysql --help | grep 'my.cnf'
返回:
order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf
2 配置slow_query开启
log_slow_queries = /var/log/mysql/mysql-slow.log (慢查询路径)
long_query_time = 5 (几秒的查询记录进日志)
log-queries-not-using-indexes = ON (没用到索引的查询记录进日志)
或者使用:
show variables like '% xx%';
cd /usr/bin (到mysql执行文件路径)
./mysql --help | grep 'my.cnf'
返回:
order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf
2 配置slow_query开启
log_slow_queries = /var/log/mysql/mysql-slow.log (慢查询路径)
long_query_time = 5 (几秒的查询记录进日志)
log-queries-not-using-indexes = ON (没用到索引的查询记录进日志)
或者使用:
show variables like '% xx%';
set global xx='Table,File';
3 输出格式
set global log_output='Table,File';
4 使用mysqldumpslow来查看日志
whereis mysqldumpslow (环境变量配置过,不用去命令目录就可以执行mysqldumpslow)
在mysqldumpslow目录下使用:mysqldumpslow -help (查看相关命令)
-s:是表示按照何种方式排序,c、t、l、r分别是按照记录次数、时间、查询时间、返回的记录数来排序(从大到小),ac、at、al、ar表示相应的倒叙.
-t: top n
-g:grep
eg:
mysqldumpslow -s c -t 10 /var/log//mysql/mysql-slow.log