Reputation: 1617
Does the command line client of mysql allow me to listen to current queries?
So i would not need to turn on logging and can check the queries for the time, i am interested to it temporarily.
Upvotes: 0
Views: 1550
Reputation: 29121
Yes login to mysql using root
user then execute following query:
SHOW FULL PROCESSLIST;
you can enable query logging to a file and then use tail -f file_name
linux command to view current queries. see here
or you can also use linux command as:
shell> watch -n1 'uptime ; mysql -u root -p'your_password' test -e"show full processlist"'
Upvotes: 1
Reputation: 65587
Assuming you are using MySQL version 5.1.16 or newer, you can temporarily enable the general query log and have it log to a table instead of a file. Then you can select from that table to get the latest query.
Here's an example:
-- capture current state
SET @old_general_log = @@global.general_log;
SET @old_log_output = @@global.log_output;
-- set log output to table instead of file
set global log_output = 'TABLE';
-- enable the general log
set global general_log = 'ON';
-- get the latest query, excluding my session
select *
from mysql.general_log
where thread_id != connection_id()
order by event_time desc
limit 1;
-- revert to previous state when done
set global general_log = @old_general_log;
set global log_output = @old_log_output;
Upvotes: 1