啟用 mysql 內的 slow-log

有時要啟用 mysql 內的 slow-log 的功能,都忘了怎麼改,記錄一下:

有二種方式

1.設置檔變更(要重啟服務)

在 /etc/my.cnf 中的 [mysqld] 段落中加上下列三列
long_query_time=1
log-slow-queries=/var/log/mysql/log-slow-queries.log
log-queries-not-using-indexes
再重啟服務即可

2.線上變更

連上MySQL

> set global slow_query_log = 'ON';
> set global log_queries_not_using_indexes = 'ON'
> set global slow_query_log_file ='/var/log/mysql/slow-query.log';
> set global long_query_time = '20';
> show variables like '%slow%';

Author: jerryw1974

learning and focus on computer science, cloud infrastructure, virtualization and information security, technical, networking,platform system and cyber-security related topic.