Search code examples
mysqlservicedaemon

MySQL general_log cannot be enabled. What am I doing wrong?


I'm on Ubuntu 18.04 with MySQL 5.7.24 and I'm trying to enable the general_log as described here.

So in my /etc/mysql/my.cnf I added this:

general_log = on
general_log_file=/tmp/mysql.log

I then stopped and started mysql again, but I get an error:

$ 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.

So I checked out 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.

In journalctl -xe I get pretty much the same.

I tried creating the log file in /tmp/mysql.log and chmodding it to 777, but after doing that, starting up mysql fails with the same errors.

Does anybody know what's wrong here?


Solution

  • In the end I solved it using this tip. Just copy pasting it here for future readers:

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

    No need to restart. The user does need the SUPER privilege (GRANT SUPER ON *.* TO user1@localhost). This works for existing and new connections on the DB and is a global setting so it works for all databases.

    It can be turned off with

    SET global general_log = 0;