Article directory
1. Error log
The error log is one of the most important logs in MySOL. It records the relevant information when mvsald starts and stops, and when any serious error occurs during the running of the server. When any fault occurs in the database and cannot be used normally, it is recommended to check it first. this log.
The log is enabled by default, stored in the directory /var/log/ by default, and the default log file name is mysqld.log. View log location:
View error log path directive
show variables like '%log_error%';
2. Binary log
The binary log (BINLOG) records all DDL (data definition language) statements and DML (data manipulation language) statements, but does not include data query (SELECT, SHOW) statements. Role: 0. Data recovery in case of disaster; @.MySOL's master-slave replication. In the MySQL8 version, the default binary log is enabled, and the parameters involved are as follows:
View binary log path directives
show variables like '%log_bin%'
Version 5.7 is not enabled by default
View log format
show variables like '%binlog_format%'.
log format | meaning |
---|---|
STATEMENT | Log records based on SQL statements, which record SQL statements, and SOL that modifies data will be recorded in log files |
RCW | Row-based logging records data changes for each row. (default) |
MIXED | A mix of STATEMENT and ROW formats, STATEMENT is used by default, and in some special cases it will automatically switch to ROW for recording |
Check the binary log
mysqlbinlog [参数选项] logfilename
Log deletion
For busy business systems, the binlog data generated every day is huge. If it is not cleared for a long time, it will take up a lot of disk space. Logs can be cleaned up in the following ways
instruction | meaning |
---|---|
reset master |
Delete all binlog logs. After deletion, the log number will restart from binlog.000001 |
purge master logs tR 'binlog' |
**** Delete all logs before the **** number |
purge master logs before 'yyyy-mm-dd hh24:mi:ss' |
Delete all logs generated before the log is "yyyy-mm-dd hh24:mi:ss" |
3. Query logs
All operation statements of the client are recorded in the query log, but the binary log does not contain SQL statements for querying data. By default, query logging is not enabled
View query log address
show variables like '%general%';
Enable query log
Modify the MySQL configuration file /etc/my.cnf file and add the following content:
#该选项用来开启查询日志 , 可选值 : 0 或者 1;0代表关闭,1代表开启
general_log=1
#设置日志的文件名,如果没有指定,默认的文件名host_name.log
general_log_file=mysql_query.log
4. Slow query log
The slow query log records the logs of all SQL statements whose execution time exceeds the setting value of the parameter long query time and the number of scanned records is not less than the min examined row limit. It is disabled by default. long_query time defaults to 10 seconds, the minimum is 0, and the precision can reach microseconds.
Slow query log address query
show global variables like ‘%slow_query_log_file%’
configuration parameters
Modify the MySQL configuration file /etc/my.cnf file and add the following content:
#慢查询日志
slow_query_log=1
#执行时间参数
long_query_time=2
By default, administrative statements are not logged, nor are queries that do not use indexes for lookups. This behavior can be changed using log_slow_admin_statements and
log queries not using indexes, as described below.
#记录执行较慢的管理语句
log_slow_admin_statements =1
#记录执行较慢的未使用索引的语句
log_queries_not_using_indexes = 1