MySQL 5.7 怎么开启慢日志

MySQL的配置路径: /etc/mysql/mysql.conf.d/mysqld.cnf

默认配置如下:

# Here you can see queries with especially long duration
#log_slow_queries       = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes

如果只是把这注释去掉,发现启动是启动不了的,错误如下:

Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.

运行 systemctl status mysql.service 查看是如下错误:

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: activating (start-post) (Result: exit-code) since Fri 2017-11-10 23:57:05 CST; 15s ago
  Process: 16048 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
  Process: 16040 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 16048 (code=exited, status=1/FAILURE);         : 16049 (mysql-systemd-s)
   CGroup: /system.slice/mysql.service
           └─control
             ├─16049 /bin/bash /usr/share/mysql/mysql-systemd-start post
             └─16108 sleep 1

Nov 10 23:57:05 xyz systemd[1]: Starting MySQL Community Server...
Nov 10 23:57:07 xyz systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE

把配置修改成下面这样,启动配置成功。

# Here you can see queries with especially long duration
slow_query_log = 1
slow_query_log_file = /var/log/mysql/mysql-slow.log
long_query_time = 3
# 下面的错误的
#log_slow_queries       = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes

详情见https://dev.mysql.com/doc/refman/5.7/en/slow-query-log.html



评论(0条)

暂时还没有评论,第一个来评论吧!


我要发表看法

引用   粗体   链接   缩进  

最近编辑

热门标签