2

mysql general_log 记录执行记录

 1 year ago
source link: https://abcdxyzk.github.io/blog/2023/02/23/mysql-general_log/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

mysql general_log 记录执行记录

2023-02-23 15:18:00

https://blog.csdn.net/weixin_39525812/article/details/116102654

http://blog.claves.cn/archives/5929

开启 general log 将所有到达MySQL Server的SQL语句记录下来。

一般不会开启开功能,因为log的量会非常庞大。但个别情况下可能会临时的开一会儿general log以供排障使用。

相关参数一共有3:general_log、log_output、general_log_file

show variables like 'general_log_file';       -- 看看日志文件保存位置
set global general_log_file='tmp/general.lg'; -- 设置日志文件保存位置

show variables like 'general_log';  -- 查看日志是否开启
set global general_log=on;          -- 开启日志功能

show variables like 'log_output';   -- 看看日志输出类型 table或file
set global log_output='table';      -- 设置输出类型为 table
set global log_output='file';       -- 设置输出类型为file

log_output = ‘FILE’ 表示将日志存入文件,默认值是FILE

log_output = ‘TABLE’ 表示将日志存入数据库,这样日志信息就会被写入到mysql.slow_log表中.

mysql查看正在执行的sql语句

show processlist;

mysql查看是否开启日志模式

show variables like '%log_output%';

show variables like '%general_log%';

保存到table

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

-- 查询
SELECT * from mysql.general_log ORDER BY event_time DESC;

-- 清空表
truncate table mysql.general_log;

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

Posted by kk

2023-02-23 15:18:00tools, mysql

« SQLServer查询执行过的SQL记录

wx_ok.pngali_ok.png

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK