工作中,需要查看mysql的top 20 慢sql,逐个进行优化,加上必要的索引。
但发现慢查询日志没有开启:
mysql> show variables like "%query%";
+------------------------------+--------------------------+
| Variable_name | Value |
+------------------------------+--------------------------+
| binlog_rows_query_log_events | OFF |
| ft_query_expansion_limit | 20 |
| have_query_cache | YES |
| long_query_time | 3.000000 |
| query_alloc_block_size | 8192 |
| query_cache_limit | 4194304 |
| query_cache_min_res_unit | 4096 |
| query_cache_size | 268435456 |
| query_cache_type | OFF |
| query_cache_wlock_invalidate | OFF |
| query_prealloc_size | 8192 |
| slow_query_log | OFF |
| slow_query_log_file | /data/log/mysql/slow.log |
+------------------------------+--------------------------+
13 rows in set (0.00 sec)
暂时使用命令
mysql> set global slow_query_log=on;开启慢查询日志,报错如下:
ERROR 29 (HY000): File ‘/data/log/mysql/slow.log‘ not found (Errcode: 13 - Permission denied
解决办法:
# cd /data/log/mysql
# touch slow.log
#chmod 777 -R slow.log
成功解决:
mysql> set global slow_query_log=on;
Query OK, 0 rows affected (0.00 sec)