mysql - 无法启用 MySQL general_log。我究竟做错了什么?
问题描述
我正在继续Ubuntu 18.04
,MySQL 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 失败并出现相同的错误。
有人知道这里有什么问题吗?
解决方案
最后我用这个技巧解决了它。只需在此处复制粘贴以供将来的读者使用:
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;
无论如何,祝大家有个美好的一天!
推荐阅读
- node.js - POSTMAN 挂起在 express/Nodejs 应用程序中发送请求
- python - 'DataFrame' 对象没有属性 'str'
- c++ - 如何将存档写入在内存中创建的磁盘?
- html - 如何将项目保持在html页面的中心
- c# - 对于多个线程来更新 List 是否是线程安全的,关于陈旧的缓存 cpu 值
按索引没有冲突? - amazon-web-services - 当回滚为假时启用 CB 是什么意思?
- c - 头函数在哪里定义?
- c++ - 互斥体是否能够执行此操作
- javascript - 通过值数组映射时如何生成 JS 倒计时的指南
- match - Excel - 如何在另一个工作表中引用带有 x 的单元格旁边的单元格?