首页 > 解决方案 > 无法启用 MySQL general_log。我究竟做错了什么?

问题描述

我正在继续Ubuntu 18.04MySQL 5.7.24我正在尝试启用此处描述的general_log功能。

所以在我的/etc/mysql/my.cnf我添加了这个:

general_log = on
general_log_file=/tmp/mysql.log

然后我停止并再次启动mysql,但出现错误:

$ sudo service mysql stop
$ sudo service mysql start
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: failed (Result: exit-code) since Fri 2019-01-04 17:50:31 CET; 45s ago
  Process: 27206 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid (code=exited, status=0/SUCCESS)
  Process: 27613 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=1/FAILURE)
 Main PID: 27208 (code=exited, status=0/SUCCESS)

Jan 04 17:50:31 librem systemd[1]: mysql.service: Failed with result 'exit-code'.
Jan 04 17:50:31 librem systemd[1]: Failed to start MySQL Community Server.
Jan 04 17:50:31 librem systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Jan 04 17:50:31 librem systemd[1]: mysql.service: Scheduled restart job, restart counter is at 5.
Jan 04 17:50:31 librem systemd[1]: Stopped MySQL Community Server.
Jan 04 17:50:31 librem systemd[1]: mysql.service: Start request repeated too quickly.
Jan 04 17:50:31 librem systemd[1]: mysql.service: Failed with result 'exit-code'.
Jan 04 17:50:31 librem systemd[1]: Failed to start MySQL Community Server.

journalctl -xe我得到几乎相同的。

我尝试在其中创建日志文件/tmp/mysql.log并将其更改为777,但在这样做之后,启动 mysql 失败并出现相同的错误。

有人知道这里有什么问题吗?

标签: mysqlservicedaemon

解决方案


最后我用这个技巧解决了它。只需在此处复制粘贴以供将来的读者使用:

SET global log_output = 'FILE';
SET global general_log_file='/var/log/mysql/general.log';
SET global general_log = 1;

无需重新启动。用户确实需要 SUPER 权限 ( GRANT SUPER ON *.* TO user1@localhost)。这适用于数据库上的现有和新连接,并且是全局设置,因此适用于所有数据库。

它可以关闭

SET global general_log = 0;

无论如何,祝大家有个美好的一天!


推荐阅读