时间:2021-05-23
1.安装MySQL
2.安装Python3
[root@localhost /]#yum install python33.下载binlog2sql文件到本地(文件在百度云盘)
[root@localhost /]#mkdir tools[root@localhost /]#cd tools[root@localhost tools]# lltotal 317440-rw-r--r--. 1 root root 317440 Sep 21 23:55 binlog2sql.tar[root@localhost tools]#tar -xvf binlog2sql.tar[root@localhost tools]#cd binlog2sql[root@localhost binlog2sql]# lltotal 52drwxr-xr-x. 3 mysql mysql 91 Jun 13 08:14 binlog2sqldrwxr-xr-x. 2 mysql mysql 54 Jun 13 07:45 example-rw-r--r--. 1 mysql mysql 35141 Jun 13 07:45 LICENSE-rw-r--r--. 1 mysql mysql 9514 Jun 13 07:45 README.md-rw-r--r--. 1 mysql mysql 54 Jun 13 07:45 requirements.txtdrwxr-xr-x. 2 mysql mysql 37 Jun 13 07:45 tests4.修改binlog2sql中的requirements.txt,把PyMySQL==0.7.11改为0.9.3,保存退出
[root@localhost binlog2sql]# vi requirements.txtPyMySQL==0.9.3wheel==0.29.0mysql-replication==0.135.安装和检查,确保是0.9.3 不然出错
[root@localhost binlog2sql]# pip3 install -r requirements.txt[root@localhost binlog2sql]# pip3 show pymysqlName: PyMySQLVersion: 0.9.3Summary: Pure Python MySQL DriverHome-page: https://github.com/PyMySQL/PyMySQL/Author: yutaka.matsubaraAuthor-email: yutaka.matsubara@gmail.comLicense: "MIT"Location: /usr/local/lib/python3.6/site-packagesRequires:1.配置文件最好加入安全目录secure-file-priv=/test,重启MySQL
[root@localhost /]# mkdir test[root@localhost /]# chown -R mysql.mysql test[root@localhost mysqldata]#vi my.cnfsecure-file-priv=/testbasedir=/application/mysqldatadir=/data/mysqlsocket=/data/mysqldata/mysql.socklog_error=/data/mysqldata/mysql8.0.errport=3306server_id=6secure-file-priv=/testautocommit=0 log_bin=/data/mysqldata/mysql-bin [root@localhost mysqldata]# systemctl start mysqld注:每个人都配置文件路径都不一样
2.进入MySQL
Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 11Server version: 8.0.20 MySQL Community Server - GPLCopyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show master status\g;+------------------+----------+--------------+------------------+-------------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |+------------------+----------+--------------+------------------+-------------------+| mysql-bin.000001 | 156 | | | |+------------------+----------+--------------+------------------+-------------------+mysql> create database csdn;mysql> use csdnmysql> insert into t1 values(1),(2),(3),(4),(5),(6),(7),(8);mysql> commit;mysql> update t1 set id=10 where id=1;mysql> delete from t1 where id=3;mysql> commit;2.开始备份库下的表的操作
2.1 查看刚才数据库csdn下的操作
2.2备份数据库csdn下的操作
[root@localhost binlog2sql]# python3 binlog2sql.py -h 192.168.0.112 -P3306 -uroot -p123 -d csdn -t t1 --start-file='mysql-bin.000001' >/test/binlog2sql.sql2.3 查看刚才备份的sql文件
[root@localhost binlog2sql]# cat /test/binlog2sql.sqlUSE b'csdn';create database csdn;USE b'csdn';create table t1 (id int);INSERT INTO `csdn`.`t1`(`id`) VALUES (1); #start 609 end 807 time 2020-09-25 02:21:21INSERT INTO `csdn`.`t1`(`id`) VALUES (2); #start 609 end 807 time 2020-09-25 02:21:21INSERT INTO `csdn`.`t1`(`id`) VALUES (3); #start 609 end 807 time 2020-09-25 02:21:21INSERT INTO `csdn`.`t1`(`id`) VALUES (4); #start 609 end 807 time 2020-09-25 02:21:21INSERT INTO `csdn`.`t1`(`id`) VALUES (5); #start 609 end 807 time 2020-09-25 02:21:21INSERT INTO `csdn`.`t1`(`id`) VALUES (6); #start 609 end 807 time 2020-09-25 02:21:21INSERT INTO `csdn`.`t1`(`id`) VALUES (7); #start 609 end 807 time 2020-09-25 02:21:21INSERT INTO `csdn`.`t1`(`id`) VALUES (8); #start 609 end 807 time 2020-09-25 02:21:21UPDATE `csdn`.`t1` SET `id`=10 WHERE `id`=1 LIMIT 1; #start 917 end 1095 time 2020-09-25 02:21:39DELETE FROM `csdn`.`t1` WHERE `id`=3 LIMIT 1; #start 917 end 1183 time 2020-09-25 02:21:483.单独查看删除语句
[root@localhost binlog2sql]# python3 binlog2sql.py -h 192.168.0.112 -P3306 -uroot -p123 -d csdn -t t1 --start-file='mysql-bin.000001' --sql-type=deleteUSE b'csdn';create database csdn;USE b'csdn';create table t1 (id int);DELETE FROM `csdn`.`t1` WHERE `id`=3 LIMIT 1; #start 917 end 1183 time 2020-09-25 02:21:484.把删除语句反转保存到sql文件中,并且查看
[root@localhost binlog2sql]# python3 binlog2sql.py -h 192.168.0.112 -P3306 -uroot -p123 -d csdn -t t1 --start-file='mysql-bin.000001' --sql-type=delete --start-position=917 --stop-position=1183 -B >/test/roll.sql[root@localhost binlog2sql]# cat /test/roll.sql INSERT INTO `csdn`.`t1`(`id`) VALUES (3); #start 917 end 1183 time 2020-09-25 02:21:485.进入MySQL,恢复被删除的数据
mysql> source /test/roll.sqlQuery OK, 1 row affected (0.00 sec)mysql> select * from t1;+------+| id |+------+| 10 || 2 || 4 || 5 || 6 || 7 || 8 || 3 |+------+8 rows in set (0.00 sec)总结
到此这篇关于mysql8.0.20配合binlog2sql的配置和简单备份恢复的步骤详解的文章就介绍到这了,更多相关mysql8.0.20 binlog2sql配置和备份恢复内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文为大家分享了mysql8.0.20winx64安装配置方法,记录如下。MySQL官网:链接直接点击链接也可以下载:mysql8.0.20解压到指定目录配置环
概述Binlog2sql是一个Python开发开源的MySQLBinlog解析工具,能够将Binlog解析为原始的SQL,也支持将Binlog解析为回滚的SQL
Win10系统下MySQL8.0.20安装和配置超详细教程MySQL下载MySQL直接去官网下载就行,选择community版本(免费)下载,链接。在selec
mysql8.0.20安装配置方法图文教程整理下,供大家参考。一、准备工作1、检查是否已经安装mysql当前计算机没有安装mysql。2、下载MySQL8.0。
MySQL下载与安装(8.0.20版)教程,供大家参考,具体内容如下MySQL官网:链接直接点击链接也可以下载:mysql8.0.20登录官网后如下图下载MyS