MySQL启用二进制日志

1、创建存储mysql二进制日志目录

mysql> system mkdir -p /app/mysql/log/binary_log
mysql> system chown -R mysql:mysql /app/mysql/log/binary_log

2、添加/etc/my.cnf 启动binary log 相关参数

log-bin=/app/mysql/log/binary_log/mysql-bin.log
expire_logs_days=10

重启mysql
systemctl restart mysqld

3、查看mysql是否设置成功

[root@kkk log]# ls -l /app/mysql/log/binary_log/
total 8
-rw-r----- 1 mysql mysql 154 Feb 20 13:44 mysql-bin.000001
-rw-r----- 1 mysql mysql  43 Feb 20 13:44 mysql-bin.index

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

mysql> show variables like 'log_bin%';
+---------------------------------+-------------------------------------------+
| Variable_name                   | Value                                     |
+---------------------------------+-------------------------------------------+
| log_bin                         | ON                                        |
| log_bin_basename                | /app/mysql/log/binary_log/mysql-bin       |
| log_bin_index                   | /app/mysql/log/binary_log/mysql-bin.index |
| log_bin_trust_function_creators | OFF                                       |
| log_bin_use_v1_row_events       | OFF                                       |
+---------------------------------+-------------------------------------------+
5 rows in set (0.00 sec)

mysql binary log 相关参数

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

mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 |      154 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.01 sec)

mysql> show binary logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000001 |       154 |
+------------------+-----------+
1 row in set (0.00 sec)

刷新日志
mysql> flush logs;
Query OK, 0 rows affected (0.03 sec)

mysql> show binary logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000001 |       201 |
| mysql-bin.000002 |       201 |
| mysql-bin.000003 |       154 |
+------------------+-----------+
3 rows in set (0.00 sec)

查看主库日志状态
mysql> show master status\G;
*************************** 1. row ***************************
             File: mysql-bin.000003
         Position: 154
     Binlog_Do_DB: 
 Binlog_Ignore_DB: 
Executed_Gtid_Set: 
1 row in set (0.00 sec)

mysql> system ls -l /app/mysql/log/binary_log
total 16
-rw-r----- 1 mysql mysql 201 Feb 20 13:48 mysql-bin.000001
-rw-r----- 1 mysql mysql 201 Feb 20 13:48 mysql-bin.000002
-rw-r----- 1 mysql mysql 154 Feb 20 13:48 mysql-bin.000003
-rw-r----- 1 mysql mysql 129 Feb 20 13:48 mysql-bin.index

你可能感兴趣的:(MySQL)