Phenomenon: Website access is getting slower and slower, and the website cannot be accessed at last. After checking, it is found that the disk is full. After careful query, it is confirmed that the binlog of mysql is too large to occupy space.
Analysis process and solution: Generally, this problem occurs when you log on to the server to check disk, memory, and process usage. top, df-h, and free-m are used to check, it is found that the disk space is full. Run the du-sh command to check the available directories and find that the binlog of mysql occupies too much space. The method for clearing binlog is as follows:
1) set Log retention period expire_logs_days to automatically delete
View the number of days for saving the current log:
Show variables like '% expire_logs_days % ';
The default value is 0, indicating that logs does not expire. You can set a global parameter to make it take effect temporarily:
Set global expire_logs_days = 7;
If BINLOG is set to be retained for only 7 days, the next restart of mysql will fail by default, so you need to set it in my. cnf
Expire_logs_days = 7
2) manually delete BINLOG (purge binary logs)
Deletes all binary logs listed in the log index before the specified log or date. These logs are also recorded in the log index file
PURGE {MASTER | BINARY} logs to 'Log _ name'
PURGE {MASTER | BINARY} logs before 'date'
For example:
Purge master logs to 'mysql-bin.010 ';
Purge master logs before '2017-06-22 13:00:00 ';
Purge master logs before DATE_SUB (NOW (), INTERVAL 3 DAY );