MySQL Client Debugging Using the General Query Log

MySQL Client Debugging Using the General Query Log

I was recently working on a project at work and needed to do some debugging on a local environment of the queries being executed against a MySQL database from the application I was working on. To accomplish this, I used the MySQL general query log, and wanted to share how to enable and configure the general query log.

For those that don’t know, the general query log is a general record of what MySQL is doing. The server writes information to this log when clients connect and disconnect, and it logs each SQL statement that is received from a connected client. The general query log can be very useful when you suspect an error and want to know exactly what queries that the client is sending to MySQL.

Note: MySQL writes SQL statements to the general query log in the order that it receives them, not necessarily the order in which they are executed.

To view information about the general_log, its location and whether or not its enabled, the following statements can be used:

To view the general query log configuration, issue the following SQL statement:

SHOW VARIABLES LIKE 'general_log%';

To enable the general query log, execute the following SQL statement:

SET GLOBAL general_log = 'ON';

To disable the general query log, execute the following SQL statement:

SET GLOBAL general_log = 'OFF';

Note: The previous statements are used to enable and disable the general query log at runtime, if you wish to enable the general query log upon startup of mysql, you’ll want to use the –log or -l options, as shown below, replacing [file_name] with a file name desired for logging.

mysqld --log=[file_name]

Author: daharveyjr

I’m a solution architect responsible for the design, development, implementation, testing, and maintenance of e-commerce operations and applications using the Hybris and WebSphere Commerce product suites and other web technologies such as Java, J2EE/JEE, Spring, PHP, WordPress and more. Twitter | Facebook | LinkedIn

Leave a Reply

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