2

MySQL - 开启日志记录

 1 year ago
source link: https://chanjarster.github.io/post/mysql/logging/
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 - 开启日志记录

MySQL 支持将 Query 和 Slow Query 日志输出到文件或者表里。

输出 Query 日志到文件(注意 Query 日志会很大,排查结束后就要关掉)(注意目录要提前建好):

SET GLOBAL general_log = 'ON';
SET GLOBAL general_log_file = '/var/log/mysql/mysql.log';

输出 Slow Query 日志到文件(注意目录要提前建好):

SET GLOBAL slow_query_log = 'ON';
SET GLOBAL slow_query_log_file = '/var/log/mysql/slow.log';

如果要把 Query 和 Slow Query 输出到表里:

SET GLOBAL log_output='TABLE,FILE';
SET GLOBAL log_error_verbosity = 1;

查询日志表:

SELECT * FROM mysql.general_log;
SELECT * FROM mysql.slow_log;

清理日志表:

TRUNCATE TABLE mysql.general_log;
TRUNCATE TABLE mysql.slow_log;

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK