Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I view live MySQL queries?

How can I trace MySQL queries on my Linux server as they happen?

For example I'd love to set up some sort of listener, then request a web page and view all of the queries the engine executed, or just view all of the queries being run on a production server. How can I do this?

like image 570
barfoon Avatar asked Feb 20 '09 06:02

barfoon


People also ask

How do I find MySQL queries?

MySQL has a statement called "show processlist" to show you the running queries on your MySQL server. This can be useful to find out what's going on if there are some big, long queries consuming a lot of CPU cycles, or if you're getting errors like "too many connections".

How can I see what queries are running on SQL Server?

You can view this by Right Clicking on Instance Name in SQL Server Management Studio and selecting “Activity Monitor”. Activity monitor tells you what the current and recent activities are in your SQL Server Instance.


1 Answers

You can log every query to a log file really easily:

mysql> SHOW VARIABLES LIKE "general_log%";  +------------------+----------------------------+ | Variable_name    | Value                      | +------------------+----------------------------+ | general_log      | OFF                        | | general_log_file | /var/run/mysqld/mysqld.log | +------------------+----------------------------+  mysql> SET GLOBAL general_log = 'ON'; 

Do your queries (on any db). Grep or otherwise examine /var/run/mysqld/mysqld.log

Then don't forget to

mysql> SET GLOBAL general_log = 'OFF'; 

or the performance will plummet and your disk will fill!

like image 50
artfulrobot Avatar answered Oct 12 '22 23:10

artfulrobot