1,查看是否打开二进制日志文件的功能
mysql> show variables like "%log_bin%";
+---------------------------------+-------+
| Variable_name | Value |
+---------------------------------+-------+
| log_bin | ON |
| log_bin_trust_function_creators | OFF |
| log_bin_trust_routine_creators | OFF |
| sql_log_bin | ON |
+---------------------------------+-------+
2,查看二进制文件的情况
mysql> show master logs;
+----------+-----------+
| Log_name | File_size |
+----------+-----------+
| 1.000001 | 141 |
| 1.000002 | 106 |
+----------+-----------+
2 rows in set (0.00 sec)
mysql> show binary logs;
+----------+-----------+
| Log_name | File_size |
+----------+-----------+
| 1.000001 | 141 |
| 1.000002 | 106 |
+----------+-----------+
2 rows in set (0.00 sec)
3,切换二进制文件
mysql> flush logs;
Query OK, 0 rows affected (0.02 sec)
mysql> show binary logs;
+----------+-----------+
| Log_name | File_size |
+----------+-----------+
| 1.000001 | 141 |
| 1.000002 | 141 |
| 1.000003 | 106 |
+----------+-----------+
3 rows in set (0.01 sec)
4,删除或者初始化二进制文件
mysql> reset master;
Query OK, 0 rows affected (0.03 sec)
mysql> show binary logs;
+----------+-----------+
| Log_name | File_size |
+----------+-----------+
| 1.000001 | 106 |
+----------+-----------+
1 row in set (0.00 sec)
5,删除指定的二进制文件
mysql> purge binary logs to '1.000003'; 删除二进制文件1.000001和1.000002
Query OK, 0 rows affected (0.48 sec)
mysql> show binary logs;
+----------+-----------+
| Log_name | File_size |
+----------+-----------+
| 1.000003 | 141 |
| 1.000004 | 141 |
| 1.000005 | 141 |
| 1.000006 | 141 |
| 1.000007 | 141 |
| 1.000008 | 106 |
+----------+-----------+
6,指定二进制日志失效期
mysql> show variables like "%expire%";
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| expire_logs_days | 0 |
+------------------+-------+
1 row in set (0.01 sec)
mysql> set global expire_logs_days=5;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like "%expire%";
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| expire_logs_days | 5 |
+------------------+-------+
1 row in set (0.00 sec)