📚 开源资源分享——颜佐光的个人书架
✉️ 联系站长
书架 / mysql / 语法

mysql查看正在执行的sql语句

2019-04-03 10:58 · 约 545 字 · 浏览 3,046 次 · 更新 2020-05-15 09:11语法

有2个方法:

1、使用processlist

但是有个弊端,就是只能查看正在执行的sql语句,对应历史记录,查看不到。好处是不用设置,不会保存。

use information_schema;
show processlist;

或者:

select * from information_schema.`PROCESSLIST` where info is not null;

2、开启日志模式

1、设置

-- 开启
SET GLOBAL log_output = 'TABLE';  
SET GLOBAL general_log = 'ON';

-- 关闭
SET GLOBAL log_output = 'TABLE';  
SET GLOBAL general_log = 'OFF';

2、查询

SELECT * from mysql.general_log ORDER BY event_time DESC

3、清空表(delete对于这个表,不允许使用,只能用truncate)

truncate table mysql.general_log;
← 返回《mysql》目录书架 →