mysql命令行怎么开启慢查询日志-LMLPHP

具体方法:

(推荐教程:mysql教程

查看一下默认慢查询的时间10秒

mysql> show variables like "%long%";         
+-----------------+-----------+
| Variable_name   | Value     |
+-----------------+-----------+
| long_query_time | 10.000000 |
+-----------------+-----------+
1 row in set (0.00 sec)
登录后复制

设置成3秒,加上global,退出再次进入生效

mysql> set global long_query_time=3;         
Query OK, 0 rows affected (0.00 sec)
登录后复制

查看一下慢查询是不是已经开启

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/mysql-slow.log |
+---------------------+---------------------------------+
4 rows in set (0.00 sec)
登录后复制

启用慢查询

mysql> set global slow_query_log='ON';          
Query OK, 0 rows affected (0.28 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/mysql-slow.log |
+---------------------+---------------------------------+
4 rows in set (0.00 sec)
登录后复制

相关推荐:php培训

以上就是mysql命令行怎么开启慢查询日志的详细内容,更多请关注Work网其它相关文章!

08-30 20:04