Mysql set the main library binlog files automatically clean up

mysql main library binlog set in open mode, it will generate in the datadir large log files, mysql default is not automatically clean up, let's set up automatic cleanup under mysql binlog file

First, open mysql

[root@push-5-221 ~]# mysql -uroot  -p -S /var/lib/mysql/3306/mysql.sock
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 18786312
Server version: 5.7.26-log MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

Second, the show binlog file

mysql> show binary logs;
| master-221.000689 | 1073742330 |
| master-221.000690 | 1073742640 |
| master-221.000691 | 1073742135 |
| master-221.000692 | 1073745009 |
| master-221.000693 | 1073752964 |
| master-221.000694 | 1073741900 |
| master-221.000695 | 1073743774 |
| master-221.000696 | 1073742434 |
| master-221.000697 | 1073765838 |
| master-221.000698 | 1073741976 |
| master-221.000699 | 1073747163 |
| master-221.000700 | 1073742572 |
| master-221.000701 | 1073742412 |
| master-221.000702 | 1073751913 |
| master-221.000703 | 1073742548 |
| master-221.000704 | 1073751141 |
| master-221.000705 | 1073742720 |
| master-221.000706 | 1073742493 |
| master-221.000707 | 1073742684 |
| master-221.000708 | 1073743787 |
| master-221.000709 | 1073742104 |
| master-221.000710 | 1073741879 |
| master-221.000711 | 1073742618 |
| master-221.000712 | 1073744563 |
| master-221.000713 | 1073741975 |
| master-221.000714 | 1073742720 |
| master-221.000715 | 1073741974 |
| master-221.000716 | 1073742362 |
| master-221.000717 | 1073742761 |
| master-221.000718 | 1073742778 |
| master-221.000719 | 1073742199 |
| master-221.000720 | 1073779470 |
| master-221.000721 | 1073741880 |
| master-221.000722 | 1073742598 |
| master-221.000723 | 1073761923 |
| master-221.000724 | 1073742172 |
| master-221.000725 | 1073743665 |
| master-221.000726 | 1073742798 |
| master-221.000727 | 1073741959 |
| master-221.000728 | 1073742084 |
| master-221.000729 | 1073742838 |
| master-221.000730 | 1073745927 |
| master-221.000731 |  903202531 |
+-------------------+------------+
731 rows in set (0.00 sec)

Display a large number of log files

To automatically delete binlog file by setting the parameter expire_logs_days

mysql> show variables like 'expire_logs_days';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| expire_logs_days | 0     |
+------------------+-------+
1 row in set (0.00 sec)

mysql> 

This parameter indicates the binlog log automatically delete / number of days past due, default value is 0, which means not automatically deleted

Is set to expire 10 days

mysql> set global expire_logs_days=10;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like 'expire_logs_days';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| expire_logs_days | 10    |
+------------------+-------+
1 row in set (0.00 sec)

mysql> 

Guess you like

Origin www.cnblogs.com/sky-cheng/p/12034767.html