Over a million developers have joined DZone.

MySQL Client Debugging Using the General Query Log

· Java Zone

Easily build powerful user management, authentication, and authorization into your web and mobile applications. Download this Forrester report on the new landscape of Customer Identity and Access Management, brought to you in partnership with Stormpath.


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]

The Java Zone is brought to you by Stormpath—a complete, pre-built User Management API. Want to learn how to use JWTs to protect microservices from CSRF and more? Check out this on-demand webinar with our Java Developer Evangelist, Micah Silverman.


Published at DZone with permission of Drew Harvey, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}