Docker系列 八.Docker下 Mysql 启动慢查询日志

harry发布

先进入mysql容器:

 docker exec -it 480c8f2a1f21 /bin/bash

进入mysql,然后输入密码即可

 mysql -u root -p

查看mysql系统参数

mysql> show variables like "%slow%";

mysql> show variables like "%slow%";
+---------------------------+--------------------------------------+
| Variable_name             | Value                                |
+---------------------------+--------------------------------------+
| log_slow_admin_statements | OFF                                  |
| log_slow_extra            | OFF                                  |
| log_slow_slave_statements | OFF                                  |
| slow_launch_time          | 2                                    |
| slow_query_log            | OFF                                  |
| slow_query_log_file       | /var/lib/mysql/480c8f2a1f21-slow.log |
+---------------------------+--------------------------------------+
6 rows in set (0.01 sec)
  • slow_query_log: off关闭状态 on开启状态
  • slow_launch_time: 默认超过2s为慢查询
  • slow_query_log_file: 慢查询日志存放地点

    这三个参数,在不同的mysql版本中,不太一样,不过都可以通过 show variables like “%slow%” 查看出来

运行如下命令即可运行慢查询日志

mysql> set global slow_query_log=ON;

Query OK, 0 rows affected (0.03 sec)
mysql> set global slow_query_log=ON;
Query OK, 0 rows affected (0.03 sec)

mysql> show variables like "%slow%";
+---------------------------+--------------------------------------+
| Variable_name             | Value                                |
+---------------------------+--------------------------------------+
| log_slow_admin_statements | OFF                                  |
| log_slow_extra            | OFF                                  |
| log_slow_slave_statements | OFF                                  |
| slow_launch_time          | 2                                    |
| slow_query_log            | ON                                   |
| slow_query_log_file       | /var/lib/mysql/480c8f2a1f21-slow.log |
+---------------------------+--------------------------------------+
6 rows in set (0.00 sec)

如果需要修改时间则设置:

mysql> set global slow_launch_time=5;
分类: docker

0 条评论

发表回复

Avatar placeholder

您的电子邮箱地址不会被公开。 必填项已用*标注