-- 检查日志开启情况 show variables like '%general_log%'; show variables like '%slow_query_log%'; -- 检查慢查询时间 show variables like '%long_query_time%'; -- 设置慢查询时间(需重新连接数据库生效) set global long_query_time = 1; -- 检查日志输出形式(FILE、TABLE、NONE) show variables like 'log_output'; -- 开启日志 set global general_log = on; set global slow_query_log = on; -- 关闭日志(调试结束一定记得清空关闭,日志容量会很大) set global general_log = off; set global slow_query_log = off; -- 设置日志输出到表 set global log_output='table'; -- 查询日志表 select * from mysql.general_log; select * from mysql.slow_log; -- 查询 select 日志(日志中的sql语句并不是直接的字符串,有点别扭) select * from (select event_time, user_host, thread_id, server_id, command_type, CONVERT(argument USING utf8) as sqlstr from mysql.general_log order by event_time desc) as log where sqlstr like 'select `%'; -- 清空 mysql 日志 truncate mysql.general_log; truncate mysql.slow_log;
参考:
https://dev.mysql.com/doc/refman/8.0/en/log-destinations.html
https://www.cnblogs.com/kerrycode/p/7130403.html
https://stackoverflow.com/questions/948174/how-do-i-convert-from-blob-to-text-in-mysql