-- 临时开启慢查询日志
show variables like '%quer%';
set global slow_query_log=1;
-- 临时开启慢查询时间
show variables like 'long_query_time';
set global long_query_time=1;
-- 设置慢查询存储的方式
show variables like 'log_output';
set global log_output = 'FILE';
set global log_output = 'TABLE';
-- 设置查看日志
SELECT * FROM mysql.slow_log;
SELECT * FROM mysql.general_log;
select sleep(30);
explain select ID from new_table;
清空sql日志
SET GLOBAL slow_query_log = 'OFF';
ALTER TABLE mysql.slow_log RENAME mysql.slow_log_drop;
CREATE TABLE mysql.slow_log LIKE mysql.slow_log_drop;
SET GLOBAL slow_query_log = 'ON';
DROP TABLE mysql.slow_log_drop;
SELECT * FROM mysql.slow_log order by start_time desc
查询运行比较慢的sql