开启Mysql慢查询
登录Mysql
mysql -urootWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1588Server version: 5.6.35-log MySQL Community Server (GPL)Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
设置成2秒,加上global,下次进mysql已然生效
mysql> set global long_query_time=2;Query OK, 0 rows affected (0.00 sec)mysql> show variables like 'long_query_time';+-----------------+----------+| Variable_name | Value |+-----------------+----------+| long_query_time | 1.000000 |+-----------------+----------+1 row in set (0.01 sec)
查看一下慢查询是不是已经开启
说明:slow_query_log OFF 说明慢查询还没有开启
mysql> show variables like "%slow%";+---------------------------+------------------------------+| Variable_name | Value |+---------------------------+------------------------------+| log_slow_admin_statements | OFF || log_slow_slave_statements | OFF || slow_launch_time | 2 || slow_query_log | OFF || slow_query_log_file | /data/mysql/root-01-slow.log |+---------------------------+------------------------------+5 rows in set (0.00 sec)
启用慢查询
mysql> set global slow_query_log='ON';Query OK, 0 rows affected (0.22 sec)
查看启用慢查询
说明:slow_query_log ON 说明慢查询开启了
mysql> show variables like "%slow%";+---------------------------+------------------------------+| Variable_name | Value |+---------------------------+------------------------------+| log_slow_admin_statements | OFF || log_slow_slave_statements | OFF || slow_launch_time | 2 || slow_query_log | ON || slow_query_log_file | /data/mysql/root-01-slow.log |+---------------------------+------------------------------+5 rows in set (0.00 sec)