How To View Live MYSQL Queries

Here’s a simple trick for viewing MySQL queries as they hit your server – enable query logging to a file and then tail -f the file:

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

view raw
log_on.sql
hosted with ❤ by GitHub

tail -f /opt/local/var/db/mysql56/out.log

view raw
tail.sh
hosted with ❤ by GitHub

Just be sure to turn it off when you’re done:

mysql> SET GLOBAL general_log = 'OFF';

view raw
log_off.sql
hosted with ❤ by GitHub