Skip to content

July 26, 2017

Log MySQL Queries

by linux

If you want to log MySQL Queries log in to your mysql client and run:

mysql> SHOW VARIABLES LIKE "general_log%";
+------------------+-----------------------+
| Variable_name    | Value                 |
+------------------+-----------------------+
| general_log      | ON                    |
| general_log_file | /var/db/mysql/machine.log |
+------------------+-----------------------+
2 rows in set (0.00 sec)
 
mysql>
mysql>
mysql> SET GLOBAL general_log = 'ON';
Query OK, 0 rows affected (0.00 sec)

Then to see the queries as soon as they run do tail on the log.

tail -f /var/db/mysql/machine.log

After you’ve seen the queries and you’ve completed the debug task it is a good practice do disable logging:

mysql> SET GLOBAL general_log = 'OFF';
Query OK, 0 rows affected (0.02 sec)
Read more from Linux Quick Tips

Leave a Reply

required
required

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments