MySQL慢查询

Windows下开启MySQL慢查询
MySQL在Windows系统中的配置文件一般是是my.ini找到[mysqld]下面加上
log-slow-queries = F:MySQLlogmysqlslowquery.log
long_query_time = 2

Linux下启用MySQL慢查询
MySQL在Windows系统中的配置文件一般是是my.cnf找到[mysqld]下面加上
log-slow-queries=/data/mysqldata/slowquery.log
long_query_time=2

注意
log-slow-queries = F:MySQLlogmysqlslowquery.log为慢查询日志存放的位置,一般这个目录要有MySQL的运行帐号的可写权限,一般都将这个目录设置为MySQL的数据存放目录;
long_query_time=2中的2表示查询超过两秒才记录;


在my.cnf或者my.ini中添加log-queries-not-using-indexes参数,表示记录下没有使用索引的查询。比如:
log-slow-queries=/data/mysqldata/slowquery.log
long_query_time=2
log-queries-not-using-indexes

mysqldumpslow命令

官方命令,方便查询慢SQL

使用Profiles分析SQL语句执行时间和消耗资源

MySQLset profiling=1; (启动profiles,默认是没开启的)

MySQLselect * from table_1 where 1=1....; (执行要分析的SQL语句)

MySQLshow profiles;

MySQLshow profile cpu,block io for query 1; (可看出SQL在各个环节的耗时和资源消耗)

使用 show engines 可查看当前MySQL支持的存储引擎详情

参考:

https://mp.weixin.qq.com/s/PfkzGnOPIEG2gnzgaTiLgA
http://kimi.it/326.html

http://kimi.it/category/mysql/

资料:

http://lib.csdn.net/base/oracle/structure
http://lib.csdn.net/base/mysql/structure

原文地址:https://www.cnblogs.com/kevin-yuan/p/7446873.html