1 数据库常用备份方案
数据库备份方案:
备份方案 | 特点 |
---|
全量备份 | 全量备份就是指对某一个时间点上的所有数据或应用进行的一个完全拷贝。 数据恢复快。 备份时间长 | 增量备份 | 增量备份是指在一次全备份或上一次增量备份后,以后每次的备份只需备份 与前一次相比增加和者被修改的文件。这就意味着,第一次增量备份的对象 是进行全备后所产生的增加和修改的文件;第二次增量备份的对象是进行第一次增量 备份后所产生的增加和修改的文件,如此类推。 没有重复的备份数据 备份时间短 恢复数据时必须按一定的顺序进行 | 差异备份 | 备份上一次的完全备份后发生变化的所有文件。 差异备份是指在一次全备份后到进行差异备份的这段时间内 对那些增加或者修改文件的备份。在进行恢复时,我们只需对第一次全量备份和最后一次差异备份进行恢复。 |
2 mysql备份工具mysqldump
mysqldump [OPTIONS] database [tables ...]
mysqldump [OPTIONS] --all-databases [OPTIONS]
mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
-uUSERNAME
-hHOST
-pPASSWORD
-P#
[root@192 ~]# mysqldump -uroot -p123 --all-databases > all-$(date '+%Y%m%f%H%M%S').sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.
[root@192 ~]# ls
all-202206%f183142.sql anaconda-ks.cfg
[root@192 ~]# mysqldump -uroot -p123 school tb_course > tb_course.sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.
[root@192 ~]# ls
all-202206%f183142.sql anaconda-ks.cfg tb_course.sql
[root@192 ~]# mysqldump -uroot -p123 school > school.sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.
[root@192 ~]# ls
all-202206%f183142.sql anaconda-ks.cfg school.sql tb_course.sql
3 mysql数据恢复
mysql> drop database school;
Query OK, 2 rows affected (0.02 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
[root@192 ~]# mysql -uroot -p123 < all-202206%f183142.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| school |
+--------------------+
4 rows in set (0.00 sec)
mysql>
mysql> drop table tb_course;
Query OK, 0 rows affected (0.00 sec)
mysql> show tables;
+------------------+
| Tables_in_school |
+------------------+
| tb_students_info |
+------------------+
1 row in set (0.00 sec)
4 差异备份与恢复
4.1 mysql差异备份
开启MySQL服务器的二进制日志功能
[root@192 ~]# vim /etc/my.cnf
[root@192 ~]# cd /opt/data
[root@192 data]# ll
总用量 123004
-rw-r-----. 1 mysql mysql 38035 6月 30 18:18 192.168.183.139.err
-rw-r-----. 1 mysql mysql 56 6月 28 20:32 auto.cnf
-rw-------. 1 mysql mysql 1680 6月 28 20:32 ca-key.pem
-rw-r--r--. 1 mysql mysql 1112 6月 28 20:32 ca.pem
-rw-r--r--. 1 mysql mysql 1112 6月 28 20:32 client-cert.pem
-rw-------. 1 mysql mysql 1680 6月 28 20:32 client-key.pem
-rw-r-----. 1 mysql mysql 328 6月 28 22:34 ib_buffer_pool
-rw-r-----. 1 mysql mysql 12582912 6月 30 19:29 ibdata1
-rw-r-----. 1 mysql mysql 50331648 6月 30 19:29 ib_logfile0
-rw-r-----. 1 mysql mysql 50331648 6月 28 20:32 ib_logfile1
-rw-r-----. 1 mysql mysql 12582912 6月 30 18:54 ibtmp1
-rw-r-----. 1 mysql mysql 4224 6月 30 08:39 localhost.err
-rw-r-----. 1 mysql mysql 15963 6月 28 21:50 localhost.localdomain.err
drwxr-x---. 2 mysql mysql 4096 6月 30 19:14 mysql
-rw-r-----. 1 mysql mysql 5 6月 30 18:18 mysql.pid
drwxr-x---. 2 mysql mysql 8192 6月 28 20:32 performance_schema
-rw-------. 1 mysql mysql 1680 6月 28 20:32 private_key.pem
-rw-r--r--. 1 mysql mysql 452 6月 28 20:32 public_key.pem
drwxr-x---. 2 mysql mysql 118 6月 30 19:27 school
-rw-r--r--. 1 mysql mysql 1112 6月 28 20:32 server-cert.pem
-rw-------. 1 mysql mysql 1676 6月 28 20:32 server-key.pem
[root@192 data]# systemctl restart mariadb
Failed to restart mariadb.service: Unit mariadb.service not found.
[root@192 data]# systemctl restart mysqld.service
[root@192 data]# ll
总用量 123020
-rw-r-----. 1 mysql mysql 46186 6月 30 19:46 192.168.183.139.err
-rw-r-----. 1 mysql mysql 56 6月 28 20:32 auto.cnf
-rw-------. 1 mysql mysql 1680 6月 28 20:32 ca-key.pem
-rw-r--r--. 1 mysql mysql 1112 6月 28 20:32 ca.pem
-rw-r--r--. 1 mysql mysql 1112 6月 28 20:32 client-cert.pem
-rw-------. 1 mysql mysql 1680 6月 28 20:32 client-key.pem
-rw-r-----. 1 mysql mysql 1084 6月 30 19:46 ib_buffer_pool
-rw-r-----. 1 mysql mysql 12582912 6月 30 19:46 ibdata1
-rw-r-----. 1 mysql mysql 50331648 6月 30 19:46 ib_logfile0
-rw-r-----. 1 mysql mysql 50331648 6月 28 20:32 ib_logfile1
-rw-r-----. 1 mysql mysql 12582912 6月 30 19:46 ibtmp1
-rw-r-----. 1 mysql mysql 4224 6月 30 08:39 localhost.err
-rw-r-----. 1 mysql mysql 15963 6月 28 21:50 localhost.localdomain.err
drwxr-x---. 2 mysql mysql 4096 6月 30 19:14 mysql
-rw-r-----. 1 mysql mysql 154 6月 30 19:46 mysql_bin.000001
-rw-r-----. 1 mysql mysql 19 6月 30 19:46 mysql_bin.index
-rw-r-----. 1 mysql mysql 7 6月 30 19:46 mysql.pid
drwxr-x---. 2 mysql mysql 8192 6月 28 20:32 performance_schema
-rw-------. 1 mysql mysql 1680 6月 28 20:32 private_key.pem
-rw-r--r--. 1 mysql mysql 452 6月 28 20:32 public_key.pem
drwxr-x---. 2 mysql mysql 118 6月 30 19:27 school
-rw-r--r--. 1 mysql mysql 1112 6月 28 20:32 server-cert.pem
-rw-------. 1 mysql mysql 1676 6月 28 20:32 server-key.pem
[root@192 ~]# mysqldump -uroot -p123 --single-transaction --flush-logs --master-data=2 --all-databases --delete-master-logs > all-$(date '+%Y%m%f%H%M%S').sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.
[root@192 ~]# ls
all-202206%f183142.sql anaconda-ks.cfg tb_course.sql
all-202206%f202155.sql school.sql
mysql> create table info(id int not null primary key auto_increment,name
varchar(10));
Query OK, 0 rows affected (0.00 sec)
mysql> insert info(name) values('tom'),('jerry'),('zhangsan');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from info;
+----+----------+
| id | name |
+----+----------+
| 1 | tom |
| 2 | jerry |
| 3 | zhangsan |
+----+----------+
3 rows in set (0.00 sec)
在school库中添加一列Linux
mysql> select * from tb_course;
+----+-------------+
| id | course_name |
+----+-------------+
| 1 | Java |
| 2 | MySQL |
| 3 | Python |
| 4 | Go |
| 5 | C++ |
| 6 | Html |
+----+-------------+
6 rows in set (0.00 sec)
mysql> insert tb_course(course_name) value('Linux');
Query OK, 1 row affected (0.00 sec)
mysql> select * from tb_course;
+----+-------------+
| id | course_name |
+----+-------------+
| 1 | Java |
| 2 | MySQL |
| 3 | Python |
| 4 | Go |
| 5 | C++ |
| 6 | Html |
| 7 | Linux |
+----+-------------+
7 rows in set (0.00 sec)
mysql> select * from tb_students_info;
+----+--------+------+------+--------+-----------+
| id | name | age | sex | height | course_id |
+----+--------+------+------+--------+-----------+
| 1 | Dany | 25 | M | 160 | 1 |
| 2 | Green | 23 | M | 158 | 2 |
| 3 | Henry | 23 | F | 185 | 1 |
| 4 | Jane | 22 | M | 162 | 3 |
| 5 | Jim | 24 | F | 175 | 2 |
| 6 | John | 21 | F | 172 | 4 |
| 7 | Lily | 22 | M | 165 | 4 |
| 8 | Susan | 23 | M | 170 | 5 |
| 9 | Thomas | 22 | F | 178 | 5 |
| 10 | Tom | 23 | F | 165 | 5 |
| 11 | Liming | 22 | M | 180 | 7 |
+----+--------+------+------+--------+-----------+
11 rows in set (0.00 sec)
mysql> update tb_students_info set height = 190 where id = 10;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from tb_students_info;
+----+--------+------+------+--------+-----------+
| id | name | age | sex | height | course_id |
+----+--------+------+------+--------+-----------+
| 1 | Dany | 25 | M | 160 | 1 |
| 2 | Green | 23 | M | 158 | 2 |
| 3 | Henry | 23 | F | 185 | 1 |
| 4 | Jane | 22 | M | 162 | 3 |
| 5 | Jim | 24 | F | 175 | 2 |
| 6 | John | 21 | F | 172 | 4 |
| 7 | Lily | 22 | M | 165 | 4 |
| 8 | Susan | 23 | M | 170 | 5 |
| 9 | Thomas | 22 | F | 178 | 5 |
| 10 | Tom | 23 | F | 190 | 5 |
| 11 | Liming | 22 | M | 180 | 7 |
+----+--------+------+------+--------+-----------+
11 rows in set (0.00 sec)
mysql> delete from tb_students_info where id = 2;
Query OK, 1 row affected (0.00 sec)
mysql> select * from tb_students_info;
+----+--------+------+------+--------+-----------+
| id | name | age | sex | height | course_id |
+----+--------+------+------+--------+-----------+
| 1 | Dany | 25 | M | 160 | 1 |
| 3 | Henry | 23 | F | 185 | 1 |
| 4 | Jane | 22 | M | 162 | 3 |
| 5 | Jim | 24 | F | 175 | 2 |
| 6 | John | 21 | F | 172 | 4 |
| 7 | Lily | 22 | M | 165 | 4 |
| 8 | Susan | 23 | M | 170 | 5 |
| 9 | Thomas | 22 | F | 178 | 5 |
| 10 | Tom | 23 | F | 190 | 5 |
| 11 | Liming | 22 | M | 180 | 7 |
+----+--------+------+------+--------+-----------+
10 rows in set (0.00 sec)
mysql>
mysql> drop database school;
Query OK, 3 rows affected (0.02 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
[root@192 ~]# mysqladmin -uroot -p123 flush-logs
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
[root@192 data]# ll
总用量 123020
-rw-r-----. 1 mysql mysql 46186 6月 30 19:46 192.168.183.139.err
-rw-r-----. 1 mysql mysql 56 6月 28 20:32 auto.cnf
-rw-------. 1 mysql mysql 1680 6月 28 20:32 ca-key.pem
-rw-r--r--. 1 mysql mysql 1112 6月 28 20:32 ca.pem
-rw-r--r--. 1 mysql mysql 1112 6月 28 20:32 client-cert.pem
-rw-------. 1 mysql mysql 1680 6月 28 20:32 client-key.pem
-rw-r-----. 1 mysql mysql 1084 6月 30 19:46 ib_buffer_pool
-rw-r-----. 1 mysql mysql 12582912 6月 30 19:46 ibdata1
-rw-r-----. 1 mysql mysql 50331648 6月 30 19:46 ib_logfile0
-rw-r-----. 1 mysql mysql 50331648 6月 28 20:32 ib_logfile1
-rw-r-----. 1 mysql mysql 12582912 6月 30 20:21 ibtmp1
-rw-r-----. 1 mysql mysql 4224 6月 30 08:39 localhost.err
-rw-r-----. 1 mysql mysql 15963 6月 28 21:50 localhost.localdomain.err
drwxr-x---. 2 mysql mysql 4096 6月 30 19:14 mysql
-rw-r-----. 1 mysql mysql 154 6月 30 20:21 mysql_bin.000003
-rw-r-----. 1 mysql mysql 19 6月 30 20:21 mysql_bin.index
-rw-r-----. 1 mysql mysql 7 6月 30 19:46 mysql.pid
drwxr-x---. 2 mysql mysql 8192 6月 28 20:32 performance_schema
-rw-------. 1 mysql mysql 1680 6月 28 20:32 private_key.pem
-rw-r--r--. 1 mysql mysql 452 6月 28 20:32 public_key.pem
drwxr-x---. 2 mysql mysql 118 6月 30 19:27 school
-rw-r--r--. 1 mysql mysql 1112 6月 28 20:32 server-cert.pem
-rw-------. 1 mysql mysql 1676 6月 28 20:32 server-key.pem
[root@192 data]# ll
总用量 123024
-rw-r-----. 1 mysql mysql 46186 6月 30 19:46 192.168.183.139.err
-rw-r-----. 1 mysql mysql 56 6月 28 20:32 auto.cnf
-rw-------. 1 mysql mysql 1680 6月 28 20:32 ca-key.pem
-rw-r--r--. 1 mysql mysql 1112 6月 28 20:32 ca.pem
-rw-r--r--. 1 mysql mysql 1112 6月 28 20:32 client-cert.pem
-rw-------. 1 mysql mysql 1680 6月 28 20:32 client-key.pem
-rw-r-----. 1 mysql mysql 1084 6月 30 19:46 ib_buffer_pool
-rw-r-----. 1 mysql mysql 12582912 6月 30 21:16 ibdata1
-rw-r-----. 1 mysql mysql 50331648 6月 30 21:16 ib_logfile0
-rw-r-----. 1 mysql mysql 50331648 6月 28 20:32 ib_logfile1
-rw-r-----. 1 mysql mysql 12582912 6月 30 20:21 ibtmp1
-rw-r-----. 1 mysql mysql 4224 6月 30 08:39 localhost.err
-rw-r-----. 1 mysql mysql 15963 6月 28 21:50 localhost.localdomain.err
drwxr-x---. 2 mysql mysql 4096 6月 30 19:14 mysql
-rw-r-----. 1 mysql mysql 1762 6月 30 21:20 mysql_bin.000003
-rw-r-----. 1 mysql mysql 154 6月 30 21:20 mysql_bin.000004
-rw-r-----. 1 mysql mysql 38 6月 30 21:20 mysql_bin.index
-rw-r-----. 1 mysql mysql 7 6月 30 19:46 mysql.pid
drwxr-x---. 2 mysql mysql 8192 6月 28 20:32 performance_schema
-rw-------. 1 mysql mysql 1680 6月 28 20:32 private_key.pem
-rw-r--r--. 1 mysql mysql 452 6月 28 20:32 public_key.pem
-rw-r--r--. 1 mysql mysql 1112 6月 28 20:32 server-cert.pem
-rw-------. 1 mysql mysql 1676 6月 28 20:32 server-key.pem
[root@192 ~]# mysql -uroot -p123 < all-202206%f202155.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql> show binlog events in 'mysql_bin.000003';
+------------------+------+----------------+-----------+-------------+----------------------------------------------------------------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+------------------+------+----------------+-----------+-------------+----------------------------------------------------------------------------------------------+
| mysql_bin.000003 | 4 | Format_desc | 10 | 123 | Server ver: 5.7.37-log, Binlog ver: 4 |
| mysql_bin.000003 | 123 | Previous_gtids | 10 | 154 | |
| mysql_bin.000003 | 154 | Anonymous_Gtid | 10 | 219 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' |
| mysql_bin.000003 | 219 | Query | 10 | 375 | use `school`; create table info(id int not null primary key auto_increment,name varchar(10)) |
| mysql_bin.000003 | 375 | Anonymous_Gtid | 10 | 440 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' |
| mysql_bin.000003 | 440 | Query | 10 | 514 | BEGIN |
| mysql_bin.000003 | 514 | Table_map | 10 | 566 | table_id: 176 (school.info) |
| mysql_bin.000003 | 566 | Write_rows | 10 | 635 | table_id: 176 flags: STMT_END_F |
| mysql_bin.000003 | 635 | Xid | 10 | 666 | COMMIT |
| mysql_bin.000003 | 666 | Anonymous_Gtid | 10 | 731 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' |
| mysql_bin.000003 | 731 | Query | 10 | 805 | BEGIN |
| mysql_bin.000003 | 805 | Table_map | 10 | 862 | table_id: 174 (school.tb_course) |
| mysql_bin.000003 | 862 | Write_rows | 10 | 908 | table_id: 174 flags: STMT_END_F |
| mysql_bin.000003 | 908 | Xid | 10 | 939 | COMMIT |
| mysql_bin.000003 | 939 | Anonymous_Gtid | 10 | 1004 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' |
| mysql_bin.000003 | 1004 | Query | 10 | 1078 | BEGIN |
| mysql_bin.000003 | 1078 | Table_map | 10 | 1148 | table_id: 175 (school.tb_students_info) |
| mysql_bin.000003 | 1148 | Update_rows | 10 | 1224 | table_id: 175 flags: STMT_END_F |
| mysql_bin.000003 | 1224 | Xid | 10 | 1255 | COMMIT |
| mysql_bin.000003 | 1255 | Anonymous_Gtid | 10 | 1320 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' |
| mysql_bin.000003 | 1320 | Query | 10 | 1394 | BEGIN |
| mysql_bin.000003 | 1394 | Table_map | 10 | 1464 | table_id: 175 (school.tb_students_info) |
| mysql_bin.000003 | 1464 | Delete_rows | 10 | 1521 | table_id: 175 flags: STMT_END_F |
| mysql_bin.000003 | 1521 | Xid | 10 | 1552 | COMMIT |
| mysql_bin.000003 | 1552 | Anonymous_Gtid | 10 | 1617 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' |
| mysql_bin.000003 | 1617 | Query | 10 | 1715 | drop database school |
| mysql_bin.000003 | 1715 | Rotate | 10 | 1762 | mysql_bin.000004;pos=4 |
+------------------+------+----------------+-----------+-------------+----------------------------------------------------------------------------------------------+
27 rows in set (0.00 sec)
[root@192 ~]# mysqladmin -uroot -p123 flush-logs
mysqladmin: [Warning] Using a password on the command line interface can
be insecure.
[root@192 ~]# mysqlbinlog --stop-position=1617 /opt/data/mysql_bin.000003
;
;
DELIMITER ;
# at 4
#220630 20:21:55 server id 10 end_log_pos 123 CRC32 0x46f3c4b5 Start: binlog v 4, server v 5.7.37-log created 220630 20:21:55
BINLOG '
Y5W9Yg8KAAAAdwAAAHsAAAAAAAQANS43LjM3LWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAEzgNAAgAEgAEBAQEEgAAXwAEGggAAAAICAgCAAAACgoKKioAEjQA
AbXE80Y=
';
# at 123
#220630 20:21:55 server id 10 end_log_pos 154 CRC32 0x5e99da3b Previous-GTIDs
# [empty]
# at 154
#220630 20:30:30 server id 10 end_log_pos 219 CRC32 0x6c644617 Anonymous_GTIDlast_committed=0 sequence_number=1 rbr_only=no
SET @@SESSION.GTID_NEXT= 'ANONYMOUS';
# at 219
#220630 20:30:30 server id 10 end_log_pos 375 CRC32 0x744af43a Query thread_id=4 exec_time=0 error_code=0
use `school`;
SET TIMESTAMP=1656592230;
SET @@session.pseudo_thread_id=4;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1;
SET @@session.sql_mode=1436549152;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1;
/*!*/;
SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=8;
SET @@session.lc_time_names=0;
SET @@session.collation_database=DEFAULT;
create table info(id int not null primary key auto_increment,name varchar(10))
;
# at 375
#220630 20:32:08 server id 10 end_log_pos 440 CRC32 0xcbbdf130 Anonymous_GTIDlast_committed=1 sequence_number=2 rbr_only=yes
/*!*/;
SET @@SESSION.GTID_NEXT= 'ANONYMOUS';
# at 440
#220630 20:32:08 server id 10 end_log_pos 514 CRC32 0xfcca279f Query thread_id=4 exec_time=0 error_code=0
SET TIMESTAMP=1656592328;
BEGIN
;
# at 514
#220630 20:32:08 server id 10 end_log_pos 566 CRC32 0x903d7ce2 Table_map: `school`.`info` mapped to number 176
# at 566
#220630 20:32:08 server id 10 end_log_pos 635 CRC32 0x3786e3b3 Write_rows: table id 176 flags: STMT_END_F
BINLOG '
yJe9YhMKAAAANAAAADYCAAAAALAAAAAAAAEABnNjaG9vbAAEaW5mbwACAw8CCgAC4nw9kA==
yJe9Yh4KAAAARQAAAHsCAAAAALAAAAAAAAEAAgAC
emhhbmdzYW6z44Y3
';
# at 635
#220630 20:32:08 server id 10 end_log_pos 666 CRC32 0x5145b313 Xid = 955
COMMIT;
# at 666
#220630 21:04:04 server id 10 end_log_pos 731 CRC32 0x78c994c7 Anonymous_GTIDlast_committed=2 sequence_number=3 rbr_only=yes
/*!*/;
SET @@SESSION.GTID_NEXT= 'ANONYMOUS';
# at 731
#220630 21:04:04 server id 10 end_log_pos 805 CRC32 0x65e4279b Query thread_id=4 exec_time=0 error_code=0
SET TIMESTAMP=1656594244;
BEGIN
;
# at 805
#220630 21:04:04 server id 10 end_log_pos 862 CRC32 0x8db9305f Table_map: `school`.`tb_course` mapped to number 174
# at 862
#220630 21:04:04 server id 10 end_log_pos 908 CRC32 0x4658400a Write_rows: table id 174 flags: STMT_END_F
BINLOG '
RJ+9YhMKAAAAOQAAAF4DAAAAAK4AAAAAAAEABnNjaG9vbAAJdGJfY291cnNlAAIDDwIeAAJfMLmN
RJ+9Yh4KAAAALgAAAIwDAAAAAK4AAAAAAAEAAgAC
';
# at 908
#220630 21:04:04 server id 10 end_log_pos 939 CRC32 0x9a360128 Xid = 958
COMMIT;
# at 939
#220630 21:10:31 server id 10 end_log_pos 1004 CRC32 0x696fe9c0 Anonymous_GTIDlast_committed=3 sequence_number=4 rbr_only=yes
/*!*/;
SET @@SESSION.GTID_NEXT= 'ANONYMOUS';
# at 1004
#220630 21:10:31 server id 10 end_log_pos 1078 CRC32 0xd355745c Query thread_id=4 exec_time=0 error_code=0
SET TIMESTAMP=1656594631;
BEGIN
;
# at 1078
#220630 21:10:31 server id 10 end_log_pos 1148 CRC32 0xeac7a187 Table_map: `school`.`tb_students_info` mapped to number 175
# at 1148
#220630 21:10:31 server id 10 end_log_pos 1224 CRC32 0x7d541890 Update_rows: table id 175 flags: STMT_END_F
BINLOG '
x6C9YhMKAAAARgAAAHwEAAAAAK8AAAAAAAEABnNjaG9vbAAQdGJfc3R1ZGVudHNfaW5mbwAGAw8B
DwMDBB4ABgA+h6HH6g==
x6C9Yh8KAAAATAAAAMgEAAAAAK8AAAAAAAEAAgAG
A1RvbRcBRr4AAAAFAAAAkBhUfQ==
';
# at 1224
#220630 21:10:31 server id 10 end_log_pos 1255 CRC32 0x7cb6226b Xid = 961
COMMIT;
# at 1255
#220630 21:14:17 server id 10 end_log_pos 1320 CRC32 0xe21f6b13 Anonymous_GTIDlast_committed=4 sequence_number=5 rbr_only=yes
/*!*/;
SET @@SESSION.GTID_NEXT= 'ANONYMOUS';
# at 1320
#220630 21:14:17 server id 10 end_log_pos 1394 CRC32 0x8db1f932 Query thread_id=4 exec_time=0 error_code=0
SET TIMESTAMP=1656594857;
BEGIN
;
# at 1394
#220630 21:14:17 server id 10 end_log_pos 1464 CRC32 0x9d225ed1 Table_map: `school`.`tb_students_info` mapped to number 175
# at 1464
#220630 21:14:17 server id 10 end_log_pos 1521 CRC32 0xe6197a37 Delete_rows: table id 175 flags: STMT_END_F
BINLOG '
qaG9YhMKAAAARgAAALgFAAAAAK8AAAAAAAEABnNjaG9vbAAQdGJfc3R1ZGVudHNfaW5mbwAGAw8B
DwMDBB4ABgA+0V4inQ==
qaG9YiAKAAAAOQAAAPEFAAAAAK8AAAAAAAEAAgAG/8ACAAAABUdyZWVuFwFNngAAAAIAAAA3ehnm
';
# at 1521
#220630 21:14:17 server id 10 end_log_pos 1552 CRC32 0xd592b65f Xid = 963
COMMIT;
# at 1552
#220630 21:16:23 server id 10 end_log_pos 1617 CRC32 0x8a00b4dc Anonymous_GTIDlast_committed=5 sequence_number=6 rbr_only=no
SET @@SESSION.GTID_NEXT= 'ANONYMOUS';
BEGIN ;
ROLLBACK ;
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' ;
DELIMITER ;
# End of log file
;
;
[root@192 ~]# mysqlbinlog --stop-position=1617 /opt/data/mysql_bin.000003 | mysql -uroot -p123
mysql: [Warning] Using a password on the command line interface can be insecure.
查看库和表
mysql> use school;
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> show tables;
+------------------+
| Tables_in_school |
+------------------+
| info |
| tb_course |
| tb_students_info |
+------------------+
3 rows in set (0.00 sec)
mysql> select * from info;
+----+----------+
| id | name |
+----+----------+
| 1 | tom |
| 2 | jerry |
| 3 | zhangsan |
+----+----------+
3 rows in set (0.00 sec)
mysql> select * from tb_course;
+----+-------------+
| id | course_name |
+----+-------------+
| 1 | Java |
| 2 | MySQL |
| 3 | Python |
| 4 | Go |
| 5 | C++ |
| 6 | Html |
| 7 | Linux |
+----+-------------+
7 rows in set (0.00 sec)
mysql> select * from tb_students_info;
+----+--------+------+------+--------+-----------+
| id | name | age | sex | height | course_id |
+----+--------+------+------+--------+-----------+
| 1 | Dany | 25 | M | 160 | 1 |
| 3 | Henry | 23 | F | 185 | 1 |
| 4 | Jane | 22 | M | 162 | 3 |
| 5 | Jim | 24 | F | 175 | 2 |
| 6 | John | 21 | F | 172 | 4 |
| 7 | Lily | 22 | M | 165 | 4 |
| 8 | Susan | 23 | M | 170 | 5 |
| 9 | Thomas | 22 | F | 178 | 5 |
| 10 | Tom | 23 | F | 190 | 5 |
| 11 | Liming | 22 | M | 180 | 7 |
+----+--------+------+------+--------+-----------+
10 rows in set (0.00 sec)
|