How to view all MySQL queries on a server
20 August 2023 (Updated 20 August 2023)
On this page
Enable logging
Locate your mysql.cnf
file and add the following configuration options.
general_log = on
general_log_file =/tmp/mysql.log # or whatever path you want
Restart your MySQL server (how you do this will depend on your platform and installation method).
Tail the log file
Run:
tail -f /tmp/mysql.log
Do some stuff in your app that triggers SQL queries and the SQL queries should then show up in your terminal as something like:
2023-08-20T11:07:35.248658Z 11 Connect root@localhost on symfony_demo_app using TCP/IP
2023-08-20T11:07:35.250345Z 11 Query SELECT a0_.id AS id_0, a0_.title AS title_1, a0_.content AS content_2 FROM article a0_ WHERE a0_.title = 'Article 1' AND a0_.content = 'Foo' AND a0_.title = 'Article 1'
2023-08-20T11:07:35.278938Z 11 Quit
Tagged:
MySQL
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment