Simple sorting of MySQL Log operation commands,
1. First confirm whether your log is enabled
MySQL>show variables like 'log_bin';
If ON is enabled, the log file is in the data directory of the MySQL installation directory.
2. How to know the current log
MySQL> show master status;
3. Use MySQLbinlog to view binary log files
shell>MySQLbinlog mail-bin.000001
Or
shell>MySQLbinlog mail-bin.000001 | tail
4. Correctly Delete MySQL BIN-LOG operations
In mysql, a large number of log files, such as mysq-bin.000001, are generated. These are binary files, if normal logs do not have master-slave configuration, you can directly use the reset master to delete the logs. This method is very simple,
If there is no master-slave replication, You can reset the database logs by reset master to clear the previous log files:
mysql> reset master;
You can also configure it in my. cnf.
expire_logs_days = 3
The number of days that binary logs are automatically deleted. Here, logs is automatically cleared three days ago.
The default value is 0, indicating "not automatically deleted ".
Example
# By file: Remove logs before mysql-bin.000354, excluding mysql-bin.000354MYSQL> purge binary logs to 'mysql-bin.000354'; Query OK, 0 rows affected (0.16 sec) # By Time: delete the log MYSQL> purge binary logs before '2017-11-10 00:00:00 '; # By Time: check the logs generated three days ago: MYSQL> purge master logs before date_sub (now (), interval 3 day); automatically clear logs: # modify my. cnf file configuration bin-log expiration time expire-logs-days = 7max-binlog-size = 268435456
If you are a master-slave mysql Log File, refer to the following method
// Before deleting logs, check the log files currently used by the master and slave servers, // log on to the mysql terminal of the server to delete the log # mysql-u root-pxxxxx // check the status of the replication master server Mysql> show master status + ------------------ + ----------- + ------------ + logs + | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | + -------------------- + ----------- + ------------------------------------------------ + | mysql-bin.000097 | 541677824 | www | test, mysql, information_schema | + ------------------ + ----------- + -------------- + -------------------------------------- + // copy the log file currently in use by the master server: mysql-bin.000097 // check the replication slave server status Mysql> show slave statusG // The replication master server log file that is currently being used by the slave server is: mysql-bin.000103 // the log file currently in use is 000097, and all I need to do is delete all the logs before 00095 (Reserved logs for recent days) mysql> purge master logs to 'mysql-bin.000095; # ll/usr/local/mysql/var // from the results, we found that all logs before 000097 have been deleted.
Articles you may be interested in:
- Summary of basic operation commands for Binary Log files in MySQL
- Mysql displays SQL statements executed by tracking logs
- How to modify the location of a mysql Log File
- Analysis and Induction of deadlock logs caused by MySQL Innodb tables
- How to view MySQL error logs