MySQL General_log 无法启用。我究竟做错了什么?

标签 mysql service daemon

我使用的是 Ubuntu 18.04MySQL 5.7.24,我正在尝试将 general_log 启用为 described here

所以在我的 /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中创建日志文件并将其chmod到777,但这样做后,启动mysql失败并出现相同的错误。

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

最佳答案

最后我用 this tip 解决了它。只需将其复制粘贴到此处以供将来的读者使用:

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;

关于MySQL General_log 无法启用。我究竟做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54043121/

相关文章:

linux - 如何安装 Proc::Daemon 模块

Mysql 没有在 where 上使用索引

php - 操作 MySQL 表中的单个产品

android - Android后台服务中的蓝牙连接?

c - 如何确保只有一个守护程序副本在运行?

java - 只要守护线程运行,如何让我的程序保持 Activity 状态?

mysql - 同时合并和连接数据

mysql - 从 VB.Net 读取和写入 SQL 信息

c# - 在我的 Windows 服务应用程序中自行托管 MVC 2 应用程序的最佳方式是什么?

android - 一段时间后停止 Android 服务?