How to Enable MySQL logging?

Created:

2016-11-16 12:50:14 UTC

Modified:

2017-08-08 13:09:21 UTC

23

Was this article helpful?


Have more questions?

Submit a request

How to Enable MySQL logging?

Applicable to:

  • Plesk for Linux

Symptoms

How to enable MySQL logging?

Resolution

Edit ' /etc/my.cnf ' (for RedHat-based systems) or ' /etc/mysql/my.cnf ' (for Debian-based systems) file.

For MySQL versions prior to 5.1

  1. Add ' log ' parameter under [mysqld] section:

    log = /path/to/log/file
  2. Make sure log file exists and has correct privileges:

    # ls -l /var/log/mysql/mysql.log
    -rw-rw---- 1 mysql root 190 Aug 21 00:29 /var/log/mysql/mysql.log
  3. Restart MySQL service:

    # /etc/init.d/mysqld restart

For MySQL version 5.1 and higher

Since version 5.1.29 the log option is deprecated.

  1. Add ' general_log ' parameters under [mysqld] section: To enable logging add the following to ' my.cnf ':

    general_log = on
    general_log_file=/path/to/query.log

    To disable or enable the general query log or change the log file name at runtime, use the global general_log and general_log_file system variables. Set general_log to 0 (or OFF ) to disable the log or to 1 (or ON ) to enable it.

    e.g.

    SET GLOBAL general_log = 'ON';
  2. Make sure log file exists and has correct privileges:

    # ls -l /var/log/mysql/mysql.log
    -rw-rw---- 1 mysql root 190 Aug 21 00:29 /var/log/mysql/mysql.log
  3. Restart MySQL service:

    # /etc/init.d/mysqld restart
Have more questions? Submit a request
Please sign in to leave a comment.