How To View Live MYSQL Queries


Ramblings on startups, NYC, advertising and hacking (mostly Python)

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 inset (.00 sec)
mysql>SET GLOBAL general_log ='ON';
Query OK, rows affected (.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

View original post 3 more words