开启 binlog
- 修改 /etc/mysql/my.cnf
(mac 本地的话,如果 /etc/mysql/my.cnf 或 /etc/my.cnf 没有, 把 ./Users/shicai.xsc/Downloads/5.7/my.cnf 拷贝到 /etc/my.cnf )
[mysqld]
log-bin=/mysql_binlog
#(必须有,不然报错,值随便设:https://blog.csdn.net/keketrtr/article/details/71209576)
server-id=1
expire-logs-days=1
- 然后
sudo mkdir /mysql_binlog
sudo chown mysql:mysql /mysql_binlog
sudo chmod 770 /mysql_binlog
- 然后
service mysql restart (mac: sudo /usr/local/mysql/support-files/mysql.server start --log-error=/Users/shicai.xsc/log)
- 然后,验证
连上 mysql,执行:show binary logs;
+---------------+-----------+
| Log_name | File_size |
+---------------+-----------+
| binlog.000001 | 4021 |
| binlog.000002 | 1997 |
| binlog.000003 | 616 |
| binlog.000004 | 1559 |
| binlog.000005 | 20717 |
+---------------+-----------+
查看 binlog 相关配置
- show variables like '%binlog_format%'; //检测 binlog 格式
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| binlog_format | ROW |
+---------------+-------+
- show master status; // 检测是否能拿到 binlog, 以及该binlog 当前的位点。
+---------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000005 | 20717 | | | |
+---------------+----------+--------------+------------------+-------------------+
- show binary logs; // 检测是否开启了 binlog
- show binlog events in 'mysql-bin.000060'; // 直接查看 binlog 内容
+---------------+------+----------------+-----------+-------------+------------------------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+---------------+------+----------------+-----------+-------------+------------------------------------------------------+
| binlog.000001 | 4 | Format_desc | 1 | 123 | Server ver: 5.7.20-log, Binlog ver: 4 |
| binlog.000001 | 123 | Previous_gtids | 1 | 154 | |
| binlog.000001 | 154 | Anonymous_Gtid | 1 | 219 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' |
| binlog.000001 | 219 | Query | 1 | 291 | BEGIN |
| binlog.000001 | 291 | Table_map | 1 | 337 | table_id: 2179 (test.a) |
| binlog.000001 | 337 | Write_rows | 1 | 385 | table_id: 2179 flags: STMT_END_F |