mysql的命令行客户端是否允许我监听当前查询?

所以我不需要打开日志记录并可以检查查询的时间,我对此很感兴趣。

最佳答案

假设您使用的是MySQL 5.1.16或更高版本,则可以临时启用常规查询日志,并将其记录到表而不是文件中。然后,您可以从该表中选择以获取最新查询。

这是一个例子:

-- 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;

关于mysql - 观看最新的mysql查询而无需登​​录,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11650472/

10-16 15:23