首页 > 数据库 >记录下闪回工具binlog2sql使用

记录下闪回工具binlog2sql使用

时间:2023-06-15 23:01:53浏览次数:60  
标签:06 记录 -- mysql binlog2sql start conf 2023 下闪回

1查看系统

[root@10-0-0-244 ~]# cat /etc/centos-release
Rocky Linux release 8.7 (Green Obsidian)

2下载MySQL

2.1更新下版本
[root@10-0-0-244 ~]# dnf update
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 2:01:36 ago on Wed Jun 14 03:59:26 2023.
Dependencies resolved.
==============================================================================================================================================================================================================================================================================================
 Package                                                                         Architecture                                          Version                                                                                 Repository                                                Size
==============================================================================================================================================================================================================================================================================================
Installing:
 kernel                                                                          x86_64                                                4.18.0-477.13.1.el8_8                                                                   baseos                                                   9.4 M
Upgrading:
 NetworkManager                                                                  x86_64                                                1:1.40.16-1.el8                                                                         baseos                                                   2.3 M
 NetworkManager-config-server                                                    noarch                                                1:1.40.16-1.el8                                                                         baseos                                                   140 k
 NetworkManager-libnm                                                            x86_64                                                1:1.40.16-1.el8                                                                         baseos                                                   1.9 M
 NetworkManager-team                                                             x86_64                                                1:1.40.16-1.el8                                                                         baseos                                                   158 k
 NetworkManager-tui                                                              x86_64                                                1:1.40.16-1.el8                                                                         baseos                                                   353 k
 abrt                                                                            x86_64                                                2.10.9-24.el8.rocky.0.1                                                                 appstream                                                540 k
 abrt-addon-ccpp                                                                 x86_64                                                2.10.9-24.el8.rocky.0.1                                                                 appstream                                                146 k
 abrt-addon-coredump-helper                                                      x86_64                                                2.10.9-24.el8.rocky.0.1                                                                 appstream                                                 53 k
 abrt-addon-kerneloops                                                           x86_64                                                2.10.9-24.el8.rocky.0.1                                                                 appstream                                                 67 k
 abrt-addon-pstoreoops                                                           x86_64                                                2.10.9-24.el8.rocky.0.1                                                                 appstream                                                 46 k
 abrt-addon-vmcore                                                               x86_64                                                2.10.9-24.el8.rocky.0.1                                                                 appstream                                                 57 k
 abrt-addon-xorg                                                                 x86_64                                                2.10.9-24.el8.rocky.0.1                                                                 appstream                                                 59 k
 abrt-cli                                                                        x86_64                                                2.10.9-24.el8.rocky.0.1                                                                 appstream                                                 36 k
 abrt-dbus
2.2安装MySQL软件包
[root@10-0-0-244 ~]# dnf install mysql-server
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 2:22:41 ago on Wed Jun 14 03:59:26 2023.
Dependencies resolved.
==============================================================================================================================================================================================================================================================================================
 Package                                                          Architecture                                              Version                                                                                        Repository                                                    Size
==============================================================================================================================================================================================================================================================================================
Installing:
 mysql-server                                                     x86_64                                                    8.0.32-1.module+el8.8.0+1283+4b88a3a8.0.1                                                      appstream                                                     32 M
Installing dependencies:
 mecab                                                            x86_64                                                    0.996-2.module+el8.8.0+1283+4b88a3a8                                                           appstream                                                    392 k
 mysql                                                            x86_64                                                    8.0.32-1.module+el8.8.0+1283+4b88a3a8.0.1                                                      appstream                                                     15 M
 mysql-common                                                     x86_64                                                    8.0.32-1.module+el8.8.0+1283+4b88a3a8.0.1                                                      appstream                                                    137 k
 mysql-errmsg                                                     x86_64                                                    8.0.32-1.module+el8.8.0+1283+4b88a3a8.0.1                                                      appstream                                                    629 k
 protobuf-lite                                                    x86_64                                                    3.5.0-15.el8                                                                                   appstream                                                    148 k
Enabling module streams:
 mysql                                                                                                                      8.0                                                                                                                                                              

Transaction Summary
==============================================================================================================================================================================================================================================================================================
Install  6 Packages

Total download size: 48 M
Installed size: 245 M
输入y继续
Is this ok [y/N]: y
2.3启动MySQL服务
[root@10-0-0-244 ~]# systemctl start mysqld
2.4验证MySQL是否运行
[root@10-0-0-244 ~]# systemctl status mysqld
● mysqld.service - MySQL 8.0 database server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2023-06-14 06:25:19 EDT; 49s ago
  Process: 761797 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
  Process: 761232 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS)
  Process: 761205 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
 Main PID: 761711 (mysqld)
   Status: "Server is operational"
    Tasks: 39 (limit: 11376)
   Memory: 442.1M
   CGroup: /system.slice/mysqld.service
           └─761711 /usr/libexec/mysqld --basedir=/usr

Jun 14 06:25:12 10-0-0-244 systemd[1]: Starting MySQL 8.0 database server...
Jun 14 06:25:12 10-0-0-244 mysql-prepare-db-dir[761232]: Initializing MySQL database
Jun 14 06:25:19 10-0-0-244 systemd[1]: Started MySQL 8.0 database server.

2.5配置MySQL安全性

[root@10-0-0-244 ~]# mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

#请输入数字以指定密码强度:
0 = 低:表示低密码强度。通常允许使用较弱的密码,可能容易被猜测或破-解。
1 = 中:表示中等密码强度。要求密码满足一些基本要求,如最小长度或字符的混合使用。
2 = 强:表示强密码强度。要求密码具有更严格的要求,如更长的长度、大写和小写字母的混合、数字和特殊字符的使用。
请根据所需的密码强度选择相应的选项数字(0、1或2),然后按 Enter 键。
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Please set the password for root here.

New password: 

Re-enter new password: 

Estimated strength of the password: 25 

#您是否希望继续使用提供的密码?若是,请按 'y' 或 'Y' 键,然后按 Enter 键。若不希望继续使用提供的密码,请按任意其他键,然后按 Enter 键。
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
 
 #错误!密码不符合当前的策略要求。这意味着您提供的密码不符合系统的密码安全策略。系统可能要求密码满足一定的长度、包含特定类型的字符(如大写字母、小写字母、数字和特殊字符)或避免常见的密码模式。请尝试选择一个更强的密码,满足系统的要求,并再次进行尝试。
 ... Failed! Error: Your password does not satisfy the current policy requirements

New password: 

Re-enter new password: 

Estimated strength of the password: 50 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

#该提示询问是否删除匿名用户。您需要选择是否删除匿名用户。如果要删除匿名用户,请按 'y' 或 'Y' 键,然后按 Enter 键。如果不想删除匿名用户,请按任意其他键,然后按 Enter 键。
Remove anonymous users? (Press y|Y for Yes, any other key for No) : 

 ... skipping.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : 

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : no

#跳过该步骤。
重新加载权限表将确保目前所做的所有更改立即生效。
 ... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

#现在重新加载权限表吗?若是,请按 'y' 或 'Y' 键,然后按 Enter 键。若不想重新加载权限表,请按任意其他键,然后按 Enter 键。
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!
2.5登录MySQL
[root@10-0-0-244 ~]# mysql -u root -p
Enter password: Pig823988
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.32 Source distribution

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
2.6创建库和表还有测试数据
mysql> create database pig;
Query OK, 1 row affected (0.00 sec)

mysql> use pig;
Database changed
mysql> CREATE TABLE test_table (
    ->   id INT,
    ->   name VARCHAR(255),
    ->   age INT,
    ->   time TIMESTAMP
    -> );
Query OK, 0 rows affected (0.03 sec)

mysql> INSERT INTO test_table (id, name, age, time) values 
    -> (1, 'John', 25, NOW()),
    -> (2, 'Alice', 30, NOW()),
    -> (3, 'Michael', 35, NOW()),
    -> (4, 'Emily', 28, NOW()),
    -> (5, 'David', 32, NOW());
Query OK, 5 rows affected (0.01 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> select * from test_table;
+------+---------+------+---------------------+
| id   | name    | age  | time                |
+------+---------+------+---------------------+
|    1 | John    |   25 | 2023-06-14 06:58:32 |
|    2 | Alice   |   30 | 2023-06-14 06:58:32 |
|    3 | Michael |   35 | 2023-06-14 06:58:32 |
|    4 | Emily   |   28 | 2023-06-14 06:58:32 |
|    5 | David   |   32 | 2023-06-14 06:58:32 |
+------+---------+------+---------------------+
5 rows in set (0.01 sec)

mysql> delete from test_table;
Query OK, 5 rows affected (0.01 sec)
2.7 找到MySQL配置文件修改
[root@10-0-0-244 ~]# cd /etc
[root@10-0-0-244 etc]# ls
DIR_COLORS               bashrc                  crontab              exports       grub2.cfg         issue.d        libpaper.d                mecabrc         nsswitch.conf.bak  pinforc    rc2.d                   sasl2           ssl                 tmpfiles.d           yum.repos.d
DIR_COLORS.256color      bindresvport.blacklist  crypto-policies      favicon.png   gshadow           issue.net      libreport                 microcode_ctl   nvme               pkcs11     rc3.d                   scl             sssd                trusted-key.key      zabbix
DIR_COLORS.lightbgcolor  binfmt.d                crypttab             filesystems   gshadow-          java           libssh                    mime.types      odbc.ini           pki        rc4.d                   screenrc        subgid              tuned                zlogin
GREP_COLORS              centos-release          csh.cshrc            firewalld     gss               jvm            libuser.conf              mke2fs.conf     odbcinst.ini       plymouth   rc5.d                   security        subgid-             udev                 zlogout
NetworkManager           chkconfig.d             csh.login            fonts         host.conf         jvm-commmon    libvirt                   modprobe.d      oddjob             pm         rc6.d                   selinux         subuid              udisks2              zprofile
PackageKit               chrony.conf             dbus-1               fprintd.conf  hostname          kdump          locale.conf               modulefiles     oddjobd.conf       polkit-1   redhat-release          sensors.d       subuid-             unbound              zshenv
X11                      chrony.keys             dconf                fstab         hosts             kdump.conf     localtime                 modules-load.d  oddjobd.conf.d     popt.d     request-key.conf        sensors3.conf   sudo-ldap.conf      updatedb.conf        zshrc
abrt                     cifs-utils              debuginfod           fuse.conf     idmapd.conf       kernel         login.defs                motd            openldap           postfix    request-key.d           services        sudo.conf           usb_modeswitch.conf
adjtime                  cloud                   default              gcrypt        infiniband-diags  keyutils       logrotate.conf            motd.d          opt                printcap   resolv.conf             sestatus.conf   sudoers             vconsole.conf
aliases                  cni                     depmod.d             gdbinit       init.d            krb5.conf      logrotate.d               mtab            os-release         profile    rhsm                    setroubleshoot  sudoers.d           vimrc
aliases.db               cockpit                 dhcp                 gdbinit.d     inittab           krb5.conf.d    lsm                       multipath       pam.d              profile.d  rocky-release           sgml            sysconfig           virc
alternatives             containers              dnf                  glvnd         inputrc           ld.so.cache    lvm                       my.cnf          papersize          protocols  rocky-release-upstream  shadow          sysctl.conf         wgetrc
anacrontab               cron.d                  dracut.conf          gnupg         iproute2          ld.so.conf     machine-id                my.cnf.d        passwd             qemu-ga    rpc                     shadow-         sysctl.d            xattr.conf
asciidoc                 cron.daily              dracut.conf.d        grafana       ipsec.conf        ld.so.conf.d   magic                     nanorc          passwd-            qemu-kvm   rpm                     shells          system-release      xdg
at.deny                  cron.deny               egl                  groff         ipsec.d           libaudit.conf  mailcap                   netconfig       pcp                rc.d       rsyslog.conf            skel            system-release-cpe  xinetd.d
audit                    cron.hourly             environment          group         ipsec.secrets     libblockdev    makedumpfile.conf.sample  networks        pcp.conf           rc.local   rsyslog.d               smartmontools   systemd             xml
authselect               cron.monthly            environment-modules  group-        iscsi             libibverbs.d   man_db.conf               nftables        pcp.env            rc0.d      rwtab.d                 sos             tcsd.conf           yum
bash_completion.d        cron.weekly             ethertypes           grub.d        issue             libnl          mcelog                    nsswitch.conf   pesign             rc1.d      samba                   ssh             terminfo            yum.conf
[root@10-0-0-244 etc]# vim my.cnf

#加上以下内容
[mysqld]
server_id = 1
log_bin = /var/log/mysql/mysql-bin.log
max_binlog_size = 1G
binlog_format = row
binlog_row_image = full
2.8查看目前的binlog文件
mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000001 |     1819 |              |                  |                   |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

3下载binlog2sql

[root@10-0-0-244 ~]# git clone https://github.com/danfengcao/binlog2sql.git && cd binlog2sql
Cloning into 'binlog2sql'...
remote: Enumerating objects: 323, done.
remote: Total 323 (delta 0), reused 0 (delta 0), pack-reused 323
Receiving objects: 100% (323/323), 153.26 KiB | 562.00 KiB/s, done.
Resolving deltas: 100% (170/170), done.
[root@10-0-0-244 binlog2sql]# ls
LICENSE  README.md  binlog2sql  example  requirements.txt  tests

[root@10-0-0-244 binlog2sql]# pip3 install -r requirements.txt
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting PyMySQL==0.7.11 (from -r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/c6/42/c54c280d8418039bd2f61284f99cb6d9e0eae80383fc72ceb6eac67855fe/PyMySQL-0.7.11-py2.py3-none-any.whl (78kB)
    100% |████████████████████████████████| 81kB 3.7MB/s 
Collecting wheel==0.29.0 (from -r requirements.txt (line 2))
  Downloading https://files.pythonhosted.org/packages/8a/e9/8468cd68b582b06ef554be0b96b59f59779627131aad48f8a5bce4b13450/wheel-0.29.0-py2.py3-none-any.whl (66kB)
    100% |████████████████████████████████| 71kB 8.3MB/s 
Collecting mysql-replication==0.13 (from -r requirements.txt (line 3))
  Downloading https://files.pythonhosted.org/packages/dd/23/384047702e694139e9fe75a8ba7ad007e8942fd119ebadabc32ce19f70f2/mysql-replication-0.13.tar.gz
Installing collected packages: PyMySQL, wheel, mysql-replication
  Running setup.py install for mysql-replication ... done
Successfully installed PyMySQL-0.7.11 mysql-replication-0.13 wheel-0.29.0

[root@10-0-0-244 binlog2sql]# pwd
/root/binlog2sql
3.1binlog2sql参数说明
[root@10-0-0-244 binlog2sql]# ls
LICENSE  README.md  binlog2sql  example  requirements.txt  tests
[root@10-0-0-244 binlog2sql]# cd binlog2sql
[root@10-0-0-244 binlog2sql]# python3 binlog2sql.py --help
usage: binlog2sql.py [-h HOST] [-u USER] [-p [PASSWORD [PASSWORD ...]]]
                     [-P PORT] [--start-file START_FILE]
                     [--start-position START_POS] [--stop-file END_FILE]
                     [--stop-position END_POS] [--start-datetime START_TIME]
                     [--stop-datetime STOP_TIME] [--stop-never] [--help]
                     [-d [DATABASES [DATABASES ...]]]
                     [-t [TABLES [TABLES ...]]] [--only-dml]
                     [--sql-type [SQL_TYPE [SQL_TYPE ...]]] [-K] [-B]
                     [--back-interval BACK_INTERVAL]

Parse MySQL binlog to SQL you want

optional arguments:
  --stop-never          Continuously parse binlog. default: stop at the latest
                        event when you start.
  --help                help information
  -K, --no-primary-key  Generate insert sql without primary key if exists
  -B, --flashback       Flashback data to start_position of start_file
  --back-interval BACK_INTERVAL
                        Sleep time between chunks of 1000 rollback sql. set it
                        to 0 if do not need sleep

connect setting:
  -h HOST, --host HOST  Host the MySQL database server located
  -u USER, --user USER  MySQL Username to log in as
  -p [PASSWORD [PASSWORD ...]], --password [PASSWORD [PASSWORD ...]]
                        MySQL Password to use
  -P PORT, --port PORT  MySQL port to use

interval filter:
  --start-file START_FILE
                        Start binlog file to be parsed
  --start-position START_POS, --start-pos START_POS
                        Start position of the --start-file
  --stop-file END_FILE, --end-file END_FILE
                        Stop binlog file to be parsed. default: '--start-file'
  --stop-position END_POS, --end-pos END_POS
                        Stop position. default: latest position of '--stop-
                        file'
  --start-datetime START_TIME
                        Start time. format %Y-%m-%d %H:%M:%S
  --stop-datetime STOP_TIME
                        Stop Time. format %Y-%m-%d %H:%M:%S;

schema filter:
  -d [DATABASES [DATABASES ...]], --databases [DATABASES [DATABASES ...]]
                        dbs you want to process
  -t [TABLES [TABLES ...]], --tables [TABLES [TABLES ...]]
                        tables you want to process

type filter:
  --only-dml            only print dml, ignore ddl
  --sql-type [SQL_TYPE [SQL_TYPE ...]]
                        Sql type you want to process, support INSERT, UPDATE,
                        DELETE.
3.1.1翻译如下:
这是 binlog2sql.py 脚本的使用说明。该脚本用于解析 MySQL binlog,并生成所需的 SQL。

以下是可用的选项和参数:

--stop-never:Continuously parse binlog. By default, it will stop at the latest event when you start.
-h HOST 或 --host HOST:MySQL database server located 的主机名或 IP 地址。
-u USER 或 --user USER:要用作登录的 MySQL 用户名。
-p [PASSWORD [PASSWORD ...]] 或 --password [PASSWORD [PASSWORD ...]]:要使用的 MySQL 密码。可以提供一个或多个密码,也可以在提示符中输入密码。
-P PORT 或 --port PORT:要使用的 MySQL 端口。
与解析范围、筛选模式和类型相关的选项还有:

--start-file START_FILE:要解析的起始 binlog 文件。
--start-position START_POS 或 --start-pos START_POS:起始文件的位置。
--stop-file END_FILE 或 --end-file END_FILE:要解析的停止 binlog 文件。默认情况下,使用 --start-file 的值。
--stop-position END_POS 或 --end-pos END_POS:停止位置。默认情况下,使用 --stop-file 的最新位置。
--start-datetime START_TIME:起始时间,格式为 %Y-%m-%d %H:%M:%S。
--stop-datetime STOP_TIME:停止时间,格式为 %Y-%m-%d %H:%M:%S。
用于筛选数据库、表和 SQL 类型的选项包括:

-d [DATABASES [DATABASES ...]] 或 --databases [DATABASES [DATABASES ...]]:要处理的数据库列表。
-t [TABLES [TABLES ...]] 或 --tables [TABLES [TABLES ...]]:要处理的表列表。
--only-dml:仅打印 DML(数据操作语言),忽略 DDL(数据定义语言)。
--sql-type [SQL_TYPE [SQL_TYPE ...]]:要处理的 SQL 类型,支持 INSERT、UPDATE、DELETE。
python binlog2sql.py 
-h ip          #指定目标ip,建议从库
-u binlog2sql  #指定数据库用户 
-p xxxx        #指定密码
-P 3306        #指定数据库端口 
-d db          #指定库名 
-t t1 t2       #需要恢复的表,多个用空格分隔
--sql-type='delete'                      #需要恢复的类型
--start-file='mysql-bin.000104'          #指定binlog文件 
--start-datetime='2020-07-16 16:46:57'   #开始时间 
--stop-datetime='2020-07-16 17:00:29'    #结束时间 
-B                                       #生成反向拼接sql
> rollback.sql                           #追加到文件

3.2 升级pymysql库

[root@10-0-0-244 binlog2sql]# pip3 install PyMySQL==0.9.3
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting PyMySQL==0.9.3
  Downloading https://files.pythonhosted.org/packages/ed/39/15045ae46f2a123019aa968dfcba0396c161c20f855f11dea6796bcaae95/PyMySQL-0.9.3-py2.py3-none-any.whl (47kB)
    100% |████████████████████████████████| 51kB 3.4MB/s 
Installing collected packages: PyMySQL
Successfully installed PyMySQL-0.9.3

4 查看误操作的SQL语句还有大致时间

[root@10-0-0-244 binlog2sql]# python3 binlog2sql.py -h127.0.0.1 -P3306 -uroot -p'Pig823988' -dpig -ttest_table --sql-type DELETE --start-file='binlog.000001' --start-datetime='2023-06-15 05:00:00' --stop-datetime='2023-06-15 06:00:00'
ALTER USER 'root'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*FB3E290798A82995827A702038527ADBED2810E3';
FLUSH PRIVILEGES;
USE b'pig';
create database pig;
USE b'pig';
create table test_table (
id int,
name varchar(255),
age int,
time timestamp
);
DELETE FROM `pig`.`test_table` WHERE `id`=1 AND `name`='John' AND `age`=25 AND `time`='2023-06-15 05:44:19' LIMIT 1; #start 1433 end 1788 time 2023-06-15 05:45:54
DELETE FROM `pig`.`test_table` WHERE `id`=2 AND `name`='Alice' AND `age`=30 AND `time`='2023-06-15 05:44:19' LIMIT 1; #start 1433 end 1788 time 2023-06-15 05:45:54
DELETE FROM `pig`.`test_table` WHERE `id`=3 AND `name`='Michael' AND `age`=35 AND `time`='2023-06-15 05:44:19' LIMIT 1; #start 1433 end 1788 time 2023-06-15 05:45:54
DELETE FROM `pig`.`test_table` WHERE `id`=4 AND `name`='Emily' AND `age`=28 AND `time`='2023-06-15 05:44:19' LIMIT 1; #start 1433 end 1788 time 2023-06-15 05:45:54
DELETE FROM `pig`.`test_table` WHERE `id`=5 AND `name`='David' AND `age`=32 AND `time`='2023-06-15 05:44:19' LIMIT 1; #start 1433 end 1788 time 2023-06-15 05:45:54
4.1 生成回滚sql并且查看新建保存的pig1.sql文件
[root@10-0-0-244 binlog2sql]# python3 binlog2sql.py -h127.0.0.1 -P3306 -uroot -p'Pig823988' --start-file='binlog.000001' --start-position=1433 --stop-position=1788 -B > pig1.sql | cat
[root@10-0-0-244 binlog2sql]# mo
modinfo             modprobe            module              modulecmd           modulemd-validator  modutil             mokutil             more                mount               mount.cifs          mount.fuse3         mountpoint          mount.smb3          
[root@10-0-0-244 binlog2sql]# more pig1.sql
INSERT INTO `pig`.`test_table`(`id`, `name`, `age`, `time`) VALUES (5, 'David', 32, '2023-06-15 05:44:19'); #start 1433 end 1788 time 2023-06-15 05:45:54
INSERT INTO `pig`.`test_table`(`id`, `name`, `age`, `time`) VALUES (4, 'Emily', 28, '2023-06-15 05:44:19'); #start 1433 end 1788 time 2023-06-15 05:45:54
INSERT INTO `pig`.`test_table`(`id`, `name`, `age`, `time`) VALUES (3, 'Michael', 35, '2023-06-15 05:44:19'); #start 1433 end 1788 time 2023-06-15 05:45:54
INSERT INTO `pig`.`test_table`(`id`, `name`, `age`, `time`) VALUES (2, 'Alice', 30, '2023-06-15 05:44:19'); #start 1433 end 1788 time 2023-06-15 05:45:54
INSERT INTO `pig`.`test_table`(`id`, `name`, `age`, `time`) VALUES (1, 'John', 25, '2023-06-15 05:44:19'); #start 1433 end 1788 time 2023-06-15 05:45:54
4.2没啥问题就执行回滚
[root@10-0-0-244 binlog2sql]# mysql -h127.0.0.1 -P3306 -uroot -p'Pig823988' < pig1.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
4.3登录MySQL确认---完成!
[root@10-0-0-244 binlog2sql]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 68
Server version: 8.0.32 Source distribution

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select * from test_table;
ERROR 1046 (3D000): No database selected
mysql> use pig
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from test_table;
+------+---------+------+---------------------+
| id   | name    | age  | time                |
+------+---------+------+---------------------+
|    5 | David   |   32 | 2023-06-15 05:44:19 |
|    4 | Emily   |   28 | 2023-06-15 05:44:19 |
|    3 | Michael |   35 | 2023-06-15 05:44:19 |
|    2 | Alice   |   30 | 2023-06-15 05:44:19 |
|    1 | John    |   25 | 2023-06-15 05:44:19 |
+------+---------+------+---------------------+
5 rows in set (0.00 sec)






















标签:06,记录,--,mysql,binlog2sql,start,conf,2023,下闪回
From: https://blog.51cto.com/u_15901780/6495536

相关文章

  • Flink1.13.6 部署踩坑记录
    环境  Hadoop集群是Ambari2.7.5的版本   Flink是1.13.6_2.12的版本问题记录  1.缺少jar包报错:ERRORorg.apache.flink.yarn.cli.FlinkYarnSessionCli[]-ErrorwhilerunningtheFlinksession.java.lang.NoClassDefFoundError:com/sun/jerse......
  • 实战:私有化部署ngin+文件步骤记录
    背景:出差到某国企进行私有化部署,一波三折。没想到是那种最麻烦的部署,导入文件需要刻光盘,进入电脑房需要上交手机,不允许有人以及拍摄设备,内部有监控摄像头。有问题怎么办?知道的自己先试试,一定也不懂的。手抄笔记本上,然后一个字一个字的敲出来。哦,对了,门口还没网,必须得往外走走。以前......
  • vue学习记录 4
    本地服务器配置apache安装学习参考网址:(官网下载apache包的时候可能会疯狂断开链接)教程里没说,但是要管理员身份操作cmd。https://blog.csdn.net/qqhruchen/article/details/127457889?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefaul......
  • python篇:在编程过程中遇到的工具问题记录
    1,用pipinstallopencv-python安装cv2后,发现pycharm中importcv2不报错,但是cv2不能点出相关函数   1>使用pipuninstallopencv-python命令,卸载了通过pip安装的cv2包   2>在https://www.lfd.uci.edu/~gohlke/pythonlibs/下载对应的安装包,例如我的python是3.8,电脑是6......
  • 今天的工作记录一下:关于centos关了防火墙却依然不能访问的问题
    今天的工作记录一下:关于centos关了防火墙却依然不能访问的问题问题在进行docker部署实验时,完成Zrlog部署之后需要进行测试,在Centos7.9内部的浏览器能访问,但是在外面的浏览器结果无法连接,尝试关闭防火墙,还是不行。猜测:猜测关闭防火墙并没有放行tomcat映射的端口,所以通过搜索引擎......
  • 隐患排查记录批量修改排查人.
    ///<summary>///隐患排查记录批量修改排查人.///</summary>///<returns></returns>[HttpGet("Yhpc")][AllowAnonymous][IgnoreLog]publicasyncTask<dynamic>Yhpc(){......
  • python中列表推导式语法问题记录
    有问题代码:w=[0,1,2]e={0:[1,2],1:[3,4],2:[5,6]}r=[dimfordimine[i]foriinw]#这一段python代码有什么问题报错:Traceback(mostrecentcalllast):File"<stdin>",line1,in<module>NameError:name'i'isnotdefined.Didyou......
  • SAP查找用户的登录记录及修改记录
    1、可以使用USR02中有个上次登陆日期和登陆时间。  2、用SE38跑下RSUSR200,输入用户名即可查询上次登陆日期 3、SU10可以查到 4、USH02可以查找用户的修改记录  ......
  • QA|如何给我们的自动化测试代码增加日志记录?|Loguru
    这里我们用的是loguru,logging虽然是自带的,但确实使用起来比较繁琐,loguru在Logging基础上增加了很多个性化功能,使用起来也比较简单,所以就使用loguru代码如下:1#cal_testlog.py23fromloguruimportlogger4fromconfigimportBASE_DIR5importtime67now_dt......
  • 记录--极致舒适的Vue可编辑表格
    这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助使用ElementPlus的Table啥都好,就是没有可编辑表格!!!......