1

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.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
  • Answered before here : http://stackoverflow.com/questions/650238/how-to-show-the-last-queries-executed-on-mysql – schaiba Apr 26 '13 at 19:22

2 Answers2

3

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).

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
nerve
  • 46
0

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'