MySQL Log File
MySQL has different types of log files (each storing different types of logs), from which you can query what MySQL has done and manage MySQL, these log files are indispensable.
1. The error log records the error information during database startup, operation, and stop;
2. isam operation log (the isam log): records all changes to the isam table. This log is only used to debug the isam mode;
3. SQL Execution log (the query log): records the client connection and the executed SQL statements;
4. Update log: the statement that records data changes. It is not recommended to use this log instead of binary logs;
5. binary log: records all statements for modifying database data;
6. The time-out log (the slow log): records all statements whose execution time exceeds the maximum SQL Execution time (long_query_time) or where no index is used;
If you are using MySQL's copy and backup functions, the slave server also provides a log file called Relay log.
By default, all log files are recorded in the MySQL data directory. You can force MySQL to close and re-open a file to record the logs. Of course, the system will automatically add a suffix (such. 00001 ,. 00002). You can run the mysql> flush logs statement in the MySQL environment, or use mysqladmin to manage the logs.ProgramRun # mysqladmin flush-logs or # mysqladmin refresh
The startup method of these logs can be followed by the option parameters when the mysqld_safe method is used to start the database, or configured in the configuration file. The second method is recommended. The configuration method is very simple, I only configured three types of logs:
[Mysqld]
Log =/var/log/mysqld_common.log
Log-error =/var/log/mysqld_err.log
Log-bin =/var/log/mysqld_bin.bin
Log Viewing is very simple. Most of the logs are text. You can directly view the logs using tools such as vim, less, and more. It is worth noting that you can view the binary files:
1) First, determine whether the binary file record function is enabled.
Mysql> show variables like 'Log _ bin ';
2) If you want to know the details of the file that records binary data, you can use the following statement to see which file is being recorded and the current location of the record:
Mysql> show Master status;
3) To view binary data, you need to use the program mysqlbinlog to see which options are supported and use them as needed.
Mysqlbinlog/var/log/MySQL/mysql-bin.000040;
You can execute the following statements to query a certain time range. If there are many records, you can direct the results to a file and read them :-):
Mysql> mysqlbinlog -- start-datetime = '2017-01-01 00:00:00 '-- stop-datetime = '2017-08-08 00:00:00'/var/log/MySQL/mysql-bin.000040>. /tmp. log