
yum install -y pip
git clone https://github.com/danfengcao/binlog2sql.git && cd binlog2sqlpip install -r requirements.txt

[mysqld]server_id = 128log_bin = /data/mysql/mysql3306/logs/mysql-binmax_binlog_size = 512Mbinlog_format = rowbinlog_row_image = full # 默认值,可以不显式设置
-- 创建用户mysql> create user data_rec@'192.168.56.%' identified by 'xxxxxxxx';Query OK, 0 rows affected (0.01 sec)-- 授权mysql> GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO data_rec@'192.168.56.%';Query OK, 0 rows affected (0.00 sec)
mysql> use testdb;Database changedmysql> create table t_test1 (id int primary key auto_increment ,c_name varchar(20), c_num int );Query OK, 0 rows affected (0.02 sec)mysql> insert into t_test1(c_name,c_num) values('aaaa',10),('abcc',15),('bacess',9),('andd',10);Query OK, 4 rows affected (0.03 sec)Records: 4 Duplicates: 0 Warnings: 0mysql> insert into t_test1(c_name,c_num) values('bbbaa',1),('dc',5),('vgcess',29),('hdgd',0);Query OK, 4 rows affected (0.01 sec)Records: 4 Duplicates: 0 Warnings: 0
mysql> select now();+---------------------+| now() |+---------------------+| 2020-09-18 16:29:08 |+---------------------+1 row in set (0.00 sec)mysql> delete from t_test1;Query OK, 8 rows affected (0.00 sec)mysql> select now();+---------------------+| now() |+---------------------+| 2020-09-18 16:29:26 |+---------------------+1 row in set (0.00 sec)
python binlog2sql.py --flashback -h 192.168.56.128 -udata_rec -p'xxxxxxxx' -d testdb -t t_test1 --start-file='mysql-bin.000003' --start-datetime='2020-09-18 16:29:08' --stop-datetime='2020-09-18 16:30:00' >/tmp/rec.sql
结果内容如下

mysql> select * from t_test1;Empty set (0.00 sec)mysql> source /tmp/rec.sql;Query OK, 1 row affected (0.00 sec)Query OK, 1 row affected (0.00 sec)Query OK, 1 row affected (0.00 sec)Query OK, 1 row affected (0.00 sec)Query OK, 1 row affected (0.00 sec)Query OK, 1 row affected (0.01 sec)Query OK, 1 row affected (0.00 sec)Query OK, 1 row affected (0.00 sec)mysql> select * from t_test1;+----+--------+-------+| id | c_name | c_num |+----+--------+-------+| 1 | aaaa | 10 || 2 | abcc | 15 || 3 | bacess | 9 || 4 | andd | 10 || 5 | bbbaa | 1 || 6 | dc | 5 || 7 | vgcess | 29 || 8 | hdgd | 0 |+----+--------+-------+8 rows in set (0.00 sec)

4. 监控利器出鞘:Prometheus+Grafana监控MySQL、Redis数据库
5. PostgreSQL主从复制--物理复制
6. MySQL传统点位复制在线转为GTID模式复制




原文作者:数据库干货铺;如有侵权,请联系管理员删除。