Enable MySQL Query Logs

I was using one of ORM tools inside my project suddenly I’ve faced a strange issue where it doesn’t do any interactions with MySQL. There’s NO errors on client side it seems queries never get executed so we wanted to listen connection/all queries coming to mysqld. I wanted to get a broader idea of what’s been going on.

I’ve checked MySQL manual and found concept of MySQL General Query Logging functionality which is spot-on for my requirement. I gave it a shot!.

This might be useful Anyone of you facing same situation as me.

MySQL General Query Log : https://dev.mysql.com/doc/refman/5.6/en/query-log.html

You can do this two ways,

1. Define in MySQL configuration file (my.cnf)
general_log = on

You might need `mysqld` reloaded once add above lines of config.

2. MySQL Run-time via executing following queries
> set global general_log_file = "/var/log/mysql/queries.log";
> set global general_log = "ON";

Having Turn on MySQL query log might consume your hard drive space a lot. I would recommend to use whenever you needs it, Turn Off when you don’t needs it to avoid issues.

Personally I always recommend to use in Run-time so you can turn it off by executing following command.

> set global general_log = "OFF";

This might help!! Use it with caution.

Leave a Reply

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