Mysql資料庫二進位制日誌的管理

stonebox1122發表於2017-05-23

如果配置了log_bin引數,則需要配置expire_logs_days引數指定二進位制日誌保留時間,不然磁碟空間早晚會被日誌佔滿的。如果之前沒有配置,則配置步驟如下:

 

1、檢視當前配置
(root@localhost)[(none)] show global variables like 'log_bin';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin       | ON    |
+---------------+-------+
1 row in set (0.02 sec)

(root@localhost)[(none)] show global variables like 'expire_logs_days';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| expire_logs_days | 0     |
+------------------+-------+
1 row in set (0.00 sec)

(root@localhost)[(none)] show global variables like 'max_binlog_size';
+-----------------+------------+
| Variable_name   | Value      |
+-----------------+------------+
| max_binlog_size | 1073741824 |
+-----------------+------------+
1 row in set (0.00 sec)

(root@localhost)[(none)] show binary logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000001 |       614 |
| mysql-bin.000002 |      1595 |
| mysql-bin.000003 | 445747850 |
+------------------+-----------+
3 rows in set (0.02 sec)

[root@dbrac16 ~]# ll /usr/local/mysql/data/mysql-bin*
-rw-r----- 1 mysql mysql       614 May 11 10:06 /usr/local/mysql/data/mysql-bin.000001
-rw-r----- 1 mysql mysql      1595 May 17 09:45 /usr/local/mysql/data/mysql-bin.000002
-rw-r----- 1 mysql mysql 445747850 May 19 14:28 /usr/local/mysql/data/mysql-bin.000003
-rw-r----- 1 mysql mysql       117 May 17 11:16 /usr/local/mysql/data/mysql-bin.index


2、檢視slave狀態
[root@dbrac17 ~]# mysql -uroot -p123456 -e "show slave status\G" | grep Master_Log_File
mysql: [Warning] Using a password on the command line interface can be insecure.
              Master_Log_File: mysql-bin.000003
        Relay_Master_Log_File: mysql-bin.000003


3、手動清除過期的日誌
如果堆積的日誌太多,可以先執行這一步,清理掉一部分日誌。
(root@localhost)[(none)] purge master logs before '2017-05-17 00:00:00';
Query OK, 0 rows affected (0.15 sec)

(root@localhost)[(none)] show binary logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000002 |      1595 |
| mysql-bin.000003 | 445747850 |
+------------------+-----------+
2 rows in set (0.00 sec)


4、配置引數
[root@dbrac16 ~]# cat /etc/my.cnf | grep expire_logs_days
expire_logs_days = 3

修改引數檔案,設定日誌保留3天,需要重啟才能生效。
直接設定,立即生效。
(root@localhost)[(none)] set global expire_logs_days=3;
Query OK, 0 rows affected (0.00 sec)

觸發過期日誌清除操作。
(root@localhost)[(none)]  flush logs;
Query OK, 0 rows affected (0.04 sec)

(root@localhost)[(none)] show binary logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000003 | 445747897 |
| mysql-bin.000004 |       201 |
+------------------+-----------+
3 rows in set (0.00 sec)

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28536251/viewspace-2139759/,如需轉載,請註明出處,否則將追究法律責任。

相關文章