If you ever need to monitor SQL queries on your local MySQL setup, you can enable general query logging with the following steps.
Enable Query Logging
First, create a log file to store the queries:
touch /Users/myuser/mysql_bin.log
Then, enter the MySQL command line and run:
SET global log_output = 'FILE';
SET global general_log_file='/Users/myuser/mysql_bin.log';
SET global general_log = 1;
Disable Logging When Done
SET global general_log = 0;
Monitoring Queries in Real Time
To filter queries related to specific tables, run:
tail -n 400 -f ~/mysql_bin.log | grep -E 'wp_options|wp_posts'
Important Notes
- Always disable logging when finished to prevent excessive log growth.
- Empty the log file occasionally to manage disk space.
- Restarting the MySQL server resets logging, so you will need to re-enable it if necessary.
Leave a Reply