标签:
mysql中最影响速度的就是那些查询很慢的语句。这些慢的语句,可能是写的不够合理或者是大数据下多表的联合查询等等。所以我们要找出这些语句,分析原因,加以优化。
1)、查看默认慢查询的时间:
mysql> show variables like "%long%"; +--------------------+-----------+ | Variable_name | Value | +--------------------+-----------+ | long_query_time | 10.000000 | | max_long_data_size | 1048576 | +--------------------+-----------+ 2 rows in set (0.24 sec)
mysql> set global long_query_time=2; Query OK, 0 rows affected (0.25 sec)
3)、查看慢查询是否开启
mysql> show variables like "%slow%"; +---------------------+-----------------------------------------+ | Variable_name | Value | +---------------------+-----------------------------------------+ | log_slow_queries | OFF | | slow_launch_time | 2 | | slow_query_log | OFF | | slow_query_log_file | /usr/local/mysql/var/li411-195-slow.log | +---------------------+-----------------------------------------+ 4 rows in set (0.23 sec)
4)、开启慢查询
mysql> set slow_query_log='ON'; ERROR 1229 (HY000): Variable 'slow_query_log' is a GLOBAL variable and should be set with SET GLOBAL
mysql> set global slow_query_log='ON'; Query OK, 0 rows affected (1.11 sec)
mysql> show variables like "%slow%"; +---------------------+-----------------------------------------+ | Variable_name | Value | +---------------------+-----------------------------------------+ | log_slow_queries | ON | | slow_launch_time | 2 | | slow_query_log | ON | | slow_query_log_file | /usr/local/mysql/var/li411-195-slow.log | +---------------------+-----------------------------------------+ 4 rows in set (4.04 sec)
long_query_time = 2 log-slow-queries = /usr/local/mysql/var/localhost-slow.log
标签:
原文地址:http://www.cnblogs.com/mengfanrong/p/5347557.html