mysql manual 15_log

mysql manual 15_log


Error log:

Check the location of the error log:

show variables like 'log_error%';
+----------------------------+----------------------------------------+
| Variable_name              | Value                                  |
+----------------------------+----------------------------------------+
| log_error                  | /var/log/mysqld.log                    |
| log_error_services         | log_filter_internal; log_sink_internal |
| log_error_suppression_list |                                        |
| log_error_verbosity        | 2                                      |
+----------------------------+----------------------------------------+

Binlog:

All DDL (data definition language) statements and DML (data manipulation statements) are recorded, but data query statements (select) are not included, which is closed by default

MySQL's master-slave replication is based on binlog

Find the location of my.cnf configuration file:

whereis my.cnf
my: /etc/my.cnf

Configure binlog in my.cnf:

#配置开启binlog日志
log_bin=binlog

#配置二进制日志的格式
binlog_format=MIXED

二进制日志的格式:
STATEMENT:	以SQL语句的形式记录
ROW:		记录的是每一行的数据变更
MIXED:		默认日志格式,混合了以上两种格式

#配置日志过期时间为3天
--expire_logs_days=3

#修改完成需要重启mysql
service mysql restart

Binlog log file save location: /var/lib/mysql
Insert picture description here

查看STATEMENT格式的日志示例:
mysqlbinlog binlog.000001

查看ROW格式的日志示例:
mysqlbinlog -vv binlog.000001

Log clearing (logs not cleared in time will take up a lot of disk space):

方式1:清除所有的日志:
reset master

方式2:删除指定编号之前的日志:
purge master logs to 'binlog.000002'

方式3:删除‘yyyy-mm-dd hh24:mi:ss'时间点之前的日志
purge master logs before 'yyyy-mm-dd hh24:mi:ss'

Query log (including additions, deletions and changes, as well as queries):

配置开启查询日志,0为关闭,1为开启
general_log=1

配置查询日志文件名(存放位置:/var/lib/mysql)
general_log_file=mysql_query_log

#修改完成需要重启mysql
service mysql restart

Slow query log:

All SQL statements whose execution time exceeds long_query_time (default 10s) are recorded

配置开启慢查询日志,0为关闭,1为开启
slow_query_log=1

配置慢查询日志文件名(存放位置:/var/lib/mysql)
slow_query_log_file=slow_query.log

配置慢查询日志的查询时间限制
long_query_time=10

#修改完成需要重启mysql
service mysql restart
查看配置的慢查询时间限制:
show variables like 'long_query_time';

Guess you like

Origin blog.csdn.net/BLU_111/article/details/108391385