Then Mysql8.0 master-slave replication operation
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| mzl |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql> use mzl;
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> create table class (id int(10) not null auto_increment, name varchar(30),grade varchar(20), primary key(id));
Query OK, 0 rows affected, 1 warning (0.04 sec)
mysql> desc class;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(10) | NO | PRI | NULL | auto_increment |
| name | varchar(30) | YES | | NULL | |
| grade | varchar(20) | YES | | NULL | |
+-------+-------------+------+-----+---------+----------------+
3 rows in set (0.01 sec)
Insert data
Use mysqldump to perform a full backup of the mzl database
[root@k8s-master1 ~]# mysqldump -uroot -p123456 --single-transaction --master-data=2 --flush-logs --flush-privileges --events --routines --all-databases > /tmp/mzldb0105.sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.
Currently the two tables share data as follows (full database)
The above is equivalent to the full data of the database at 23:50 in the evening
Now class and class02 re-insert the new data, the equivalent of 1 February-4 pm: 5 0 subsequent to 1 January 5 morning 12 : 00 before data
mysql> insert into class02 values (3,'jim',' one year in elementary school '),(4,'tom',' graduate ');
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> insert into class values (25,' General Manager Tian ',' Doctor '),(26,' General Manager Fan ',' Senior Year ');
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
Remove mzl library
mysql> drop database mzl;
Fully import using mysqldump
mysql> create database mzl;
Query OK, 1 row affected (0.00 sec)
mysql> source /tmp/mzldb0105.sql
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
View full data
After the full import, the data is incomplete, and there is no data inserted later, then use mysqlbinlog to perform incremental recovery on the binary log
The most important thing for mysqlbinlog to perform incremental log recovery is to determine the starting position (start-position) and ending position (stop-position) to be restored . The starting position (start-position) is the position after we perform the full backup, and the termination The location is the location before the fault occurred.
[root@k8s-master1 tmp]# more mzldb0105.sql
-- Position to start replication or point-in-time recovery from
-- CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000005', MASTER_LOG_POS=191;
To confirm that you want to restore the end position, that is , the position before executing "DROP DATABASE LIJIAMAN" , you need to confirm in binlog .
[root@k8s-master1 mysql]# mysqlbinlog --no-defaults --base64-output=DECODE-ROWS -v -v mysql-bin.000005 > mzl-bin.txt
[root@k8s-master1 mysql]# more mzl-bin.txt
Determine the start and end points, perform incremental recovery
Start: 191 of the mysql-bin.000005 log
End: 861 of the mysql-bin.000005 file
Restore mysqlbinlog
[root@k8s-master1 mysql]# mysqlbinlog --no-defaults --start-position=191 --stop-position=958 /data/mysql/mysql/mysql-bin.000005 |mysql -uroot -p123456
Related Reading:
Mysql8.0 master-slave replication
Mysql8.0 installation actual combat