MySQL general log

Published under MySQL.

📺  Click here to skip to the video attached to this post  👇

The general log records every query that the MySQL database processes, with the parameters visible. This means you are able to see the values used in a bound query.

There are two ways to enable the MySQL general log:

  1. Enable it in the configuration file. This will enable the general log when MySQL starts.

  2. You can run a global query to enable the general log while the MySQL server is running.

Enable via configuration file

To enable the general log via the configuration file, add the following to your configuration file (example path is /etc/my.cnf):

You must restart the MySQL server after editing the configuration file.

Enable via a global query

To enable the general log via a global query, you can run this query:

General query log location

Now that the general log is enabled, you have a couple options on where the log is written to. By default, it’s written to a log file located at: /var/log/mysql/mysql.log

However, when I enable the general log for debugging, I often have the output written to a table, so I can query it easily. To write the output to a table, you can run this global query:

You can query the general log table via:

The results returned can be filtered, sorted, etc:


Thanks for reading!

Did you find this post useful? Let me know on Twitter! If you found an issue with the content, submit a pull request!

Subscribe to my newsletter to know when I publish more content in the future.

❤️ Likes: 6
📣 Retweets: 8
💬 Replies: 0
🙊 Mentions: 0