Over a million developers have joined DZone.

MySQL Client Debugging Using the General Query Log

· Java Zone

Navigate the Maze of the End-User Experience and pick up this APM Essential guide, brought to you in partnership with CA Technologies

cat_mysql

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]


Thrive in the application economy with an APM model that is strategic. Be E.P.I.C. with CA APM.  Brought to you in partnership with CA Technologies.

Topics:

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.

SEE AN EXAMPLE
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.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}