How do I view the last run queries in MySQL in a live feed format?

I want to leave my terminal window open and just have MySQL queries pop up on the screen whenever something is run. I know I can do it with the tail command, but I'm not sure where the MySQL logs are stored. I can also do mysqladmin proc, but that doesn't give me a continuous live feed.


You have a couple of options here. You can enable general query logging for MySQL, by adding:

 log = /path/to/your/log.log

to your my.cnf (typically /etc/my.cnf) and restarting. You can then tail it as needed. I wouldn't necessarily recommend this, as that log can grow quite large over time.

Your second option, as you had mentioned is to use watch in conjunction with mysqladmin proc. For example, you can use:

 watch -n.5 'mysqladmin proc stat'

to show you the process list and status every half second. You can change -n.5 to suit your specific needs (I prefer adding stat to the line to give the extra information, which can sometimes be helpful).

|improve this answer|||||

All queries are written to a file on the system called ".mysqlhistory". You can run the below command to actively view the queries being ran on your DB.

find / -name ".mysqlhistory" -exec 'tail -f'

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.