mysql命令行开启慢查询日志的方法:执行【set global slow_query_log='ON';】语句即可开启。通过执行【show variables like "%slow%";】语句可以检查慢查询日志是否已开启。
具体方法:
(推荐教程: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命令行怎么开启慢查询日志的详细内容,更多请关注名铺123其它相关文章!