Mysql 8 日志处理

— 查看通用日志查询是否开启
show variables like ‘%general%’;
show variables like ‘%slow_query%’;

— 查看当前慢查询日志输出的格式
show variables like ‘%log_output%’;

— 开启通用日志查询:
set global general_log=on;

— 关闭通用日志查询:
set global general_log=off;

— 设置通用日志输出为表方式:
set global log_output=’TABLE’;

— 设置通用日志输出为文件方式:
set global log_output=’FILE’;

— 设置通用日志输出为表和文件方式:
set global log_output=’FILE,TABLE’;

— 当前慢查询日志的开启情况
show variables like ‘%quer%’;

— 查看/清理日志
select * from mysql.general_log;
select * from mysql.slow_log;

— 测试慢查询
SELECT SLEEP(3)

my.ini配置

[Client]
port = 3306

[mysqld]

port = 3306

basedir=D:\Java\mysql-8.0.15

datadir=D:\Java\mysql-8.0.15\data

max_connections=200

character-set-server=utf8

default-storage-engine=INNODB

log_bin_trust_function_creators=1

general_log=1

general_log_file=D:\Java\mysql-8.0.15\log\log.txt

slow_query_log=ON

slow_query_log_file=D:\Java\mysql-8.0.15\log\log-slow.txt

long_query_time=2

log_output=FILE,TABLE

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

[mysql]

default-character-set=utf8

ˆ Back To Top