我正在使用MySQL服务器版本:5.5.8-log MySQL社区服务器(GPL)
我想记录不使用INDEX的查询,也很慢!
我在这里复制我的my.ini设置.
[mysqld]
port = 3306
log ="E:/wamp/logs/genquery.log"
log_slow_queries
long_query_time = 1
slow_query_log = 1
slow_query_log_file ="E:/wamp/logs/slowquery.log"
我需要做些什么改变?
小智 6
log_queries_not_using_indexes
Command-Line Format --log-queries-not-using-indexes
Option-File Format log-queries-not-using-indexes
Option Sets Variable Yes, log_queries_not_using_indexes
Variable Name log_queries_not_using_indexes
Variable Scope Global
Dynamic Variable Yes
Permitted Values
Type boolean
Run Code Online (Sandbox Code Playgroud)
是否将不使用索引的查询记录到慢查询日志中.见5.2.4节,
对Linux用户可能有用.(Testet:Ubuntu 16.04)
获取终端root并编辑mysql配置
su
vim /etc/mysql/conf.d/mysql.cnf
[mysqld]
slow_query_log=1
slow_query_log_file=/var/log/mysql/slow-query.log
long_query_time=1
log_queries_not_using_indexes=1
Run Code Online (Sandbox Code Playgroud)
添加日志文件并重启mysql服务器
touch /var/log/mysql/slow-query.log
chown mysql:adm /var/log/mysql/slow-query.log
chmod 640 slow-query.log
service mysql restart
Run Code Online (Sandbox Code Playgroud)
使用SQL查询测试慢速日志记录
/* Activate query log - Maybe useful to show errors (not necessary) */
SET GLOBAL SLOW_QUERY_LOG=ON;
/* Check if slow query log is working */
SELECT SLEEP(2);
Run Code Online (Sandbox Code Playgroud)