查看mysql执行sql语句中慢的部分
本次配置/etc/my.cnf中,在[mysqld]部分中增加:
#query结果集缓存,慎用
query_cache_size = 134217728
query_cache_type=1
query_cache_limit=1048576
#慢sql日志配置
slow_query_log_file=/var/run/mysqld/slowquery.log
#多久算慢sql配置,单位秒
long_query_time=5
#是否开启慢sql
slow_query_log=1
#是否对未使用索引的sql进行记录
log_queries_not_using_indexes=1
重启MySQL服务,在MySQL shell中验证配置是否生效:
mysql> show variables like ‘%quer%’;
+——————————-+——————————-+
| Variable_name | Value |
+——————————-+——————————-+
| ft_query_expansion_limit | 20 |
| have_query_cache | YES |
| log_queries_not_using_indexes | ON |
| log_slow_queries | ON |
| long_query_time | 5.000000 |
| query_alloc_block_size | 8192 |
| query_cache_limit | 1048576 |
| query_cache_min_res_unit | 4096 |
| query_cache_size | 134217728 |
| query_cache_type | ON |
| query_cache_wlock_invalidate | OFF |
| query_prealloc_size | 8192 |
| slow_query_log | ON |
| slow_query_log_file | /var/run/mysqld/slowquery.log |
+——————————-+——————————-+
14 rows in set (0.00 sec)