How to manage mysql binary logs
This article focuses on "how to manage mysql binary logs". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to manage mysql binary logs.
Use parameters to automatically clear binary logs
By default, MySQL does not remove old binary logs that are not running. The expire_logs_days parameter automatically removes binary logs. The default value of this parameter is 0, which means
The binary log is not automatically removed. Assigning a value greater than 0 to this parameter removes logs that are greater than this value, in days.
Manually clear the binary log
Clear specific files
Click (here) to collapse or open
Mysql > purge binary logs to 'mysql-bin-3306.000005'
Query OK, 0 rows affected (0.08 sec)
Clear a specific log or time
Click (here) to collapse or open
Mysql > purge binary logs before '2017-09-25 1215 30 purl 00'
Query OK, 0 rows affected (0.01 sec)
Physically delete binary log
Rm-rf mysql-bin-3306.000005
Click (here) to collapse or open
Mysql > show master logs
+-+ +
| | Log_name | File_size |
+-+ +
| | mysql-bin-3306.000005 | 0 | |
| | mysql-bin-3306.000006 | 604 |
| | mysql-bin-3306.000007 | 891 | |
| | mysql-bin-3306.000008 | 346 |
| | mysql-bin-3306.000009 | 35946018 | |
+-+ +
If a binary log is deleted directly from the file system, even if the file is no longer in the file system, MySQL will display a pointer in a file with 0 bytes. Later, when you use the purge command to delete the binary log again, you will have the following prompt:
Click (here) to collapse or open
Mysql > purge binary logs to 'mysql-bin-3306.000006'
Query OK, 0 rows affected, 1 warning (0.02 sec)
Mysql > show warings\ G
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'warings' at line 1
Mysql > show master logs
+-+ +
| | Log_name | File_size |
+-+ +
| | mysql-bin-3306.000006 | 604 |
| | mysql-bin-3306.000007 | 891 | |
| | mysql-bin-3306.000008 | 346 |
| | mysql-bin-3306.000009 | 35946018 | |
+-+ +
4 rows in set (0.00 sec)
At this point, I believe you have a deeper understanding of "how to manage mysql binary logs". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!