Enabling Global MySQL Log in Ubuntu


If you use (You should!) MySQL Prepared Statements, you may not be able to see how the final MySQL queries looks like, within your application, with all the bindings put into place. This is how to view them:

Note

This should never be done in production environments.

Even in development environments, you should revert the changes as soon as you are done with your task.

The reason for this is that, when enabled, this tweak records all queries run in the MySQL system. All of them! The log file can and will get too big, and I suspect the performance of MySQL will degrade too.

How To

  1. Open /etc/mysql/mysql.conf.d/mysqld.cnf.
  2. Set general_log_file to /var/log/mysql/mysql.log.
  3. Set general_log to 1 (True).
  4. Now you can view the log in the above mentioned path.

You can periodically empty the file to only be left with the new changes.

, , ,

Leave a Reply

Your email address will not be published. Required fields are marked *