CentOS-7.5 build MySQL master-slave replication

First, the experimental environment
two similarly configured virtual machine CentOS-7.5;
both VM + selinux firewalls are closed;
two or more external network can be a virtual machine;
Master: the CentOS-. 1 (192.168.218.128)
Slave: CentOS- 2 (192.168.218.136)

Second, build a master-slave replication
1) Two simultaneous MySQL server installation services
Description: Because I've written before "CentOS-7.5 Community Edition install MySQL-5.7" this stuff, so this is not done in a repetitive motion; two operating virtual machine to install the MySQL service is exactly the same, you can copy and paste directly
Bowen link to: https://blog.51cto.com/14783377/2485030

2) Modify the two profile MySQL
master terminal as follows:
CentOS-7.5 build MySQL master-slave replication

slave end as follows:
CentOS-7.5 build MySQL master-slave replication

Remember: After you finish modifying the configuration file, restart the MySQL service should validate the configuration

3)mysql主服务器初始化以后的第一次全备
[root@CentOS-1 ~]#
[root@CentOS-1 ~]# mysqldump -uroot -p'Mysql.2020' --all-databases --single-transaction > /tmp/mysql_all.sql #数据库第一次全量备份
mysqldump: [Warning] Using a password on the command line interface can be insecure.
Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed suppressed parts of the database. If you don't want to restore GTIDs, pass --set-gtid-purged=OFF. To make a complete dump, pass --all-databases --triggers --routines --events.
[root@CentOS-1 ~]#
[root@CentOS-1 ~]#
[root@CentOS-1 ~]# ll /tmp | grep 'mysql*'
CentOS-7.5 build MySQL master-slave replication

4) the first mysql master server all at once from the server to the standby copy
[the root-the CentOS @ ~. 1] #
[the root-the CentOS @ ~. 1] # SCP /tmp/mysql_all.sql [email protected]: / tmp / # whole database backup file copied from the master to the slave
CentOS-7.5 build MySQL master-slave replication

In the view from the server:
[the root @ ~ the CentOS-2] #
[2-the CentOS the root @ ~] # LL / tmp | grep '* MySQL'
CentOS-7.5 build MySQL master-slave replication

5) In all equipment from the server to restore
[the root @ ~ the CentOS-2] #
[2-the CentOS the root @ ~] # MySQL -uroot--p'Mysql.2020 '</tmp/mysql_all.sql
MySQL: [Warning] The password ON A Command the using Line interface CAN BE in the insecure.
[2-the CentOS the root @ ~] #

In this case, master end and a slave end of the data in a consistent state

6) from the master authorization server

Primary server side:
[the root-the CentOS @ ~. 1] #
[the root-the CentOS @ ~. 1] # MySQL -uroot--p'Mysql.2020 '
MySQL>
MySQL> Grant Replication Slave ON . To [email protected] by IDENTIFIED 'Mysql.2019'; # repluser authorized account can be replicated from a master server 192.168.218.136 all libraries and all tables
OK Query, 0 rows affected, 1 warning (0.00 sec)

MySQL>
MySQL> flush privileges; # refresh permission
Query OK, 0 rows affected (0.00 sec)

mysql>
CentOS-7.5 build MySQL master-slave replication

From the server performs:
[the root @ ~ the CentOS-2] #
[2-the CentOS the root @ ~] # MySQL -uroot--p'Mysql.2020 '
MySQL>
MySQL> = Change Master MASTER_HOST to' 192.168.218.128 ', MASTER_USER = 'repluser', master_password = 'Mysql.2019', = master_auto_position. 1;
Query the OK, 0 rows affected, 2 Represents warnings (0.11 sec)

mysql>
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)

MySQL>
MySQL> Show slave Status \ G # View slave status
CentOS-7.5 build MySQL master-slave replication

Third, verify master-slave synchronization is successful

Ideas: If you insert or delete SQL statements, the same effect can occur at the end of the slave master end then it had any brains master-slave synchronization configuration is successful

1) Before validation, the first comparison data is consistent master and slave
master server side:
[the root @ ~ the CentOS-1] #
[@ the CentOS the root-1 ~] # MySQL -uroot--p'Mysql.2020 'master log #
MySQL>
MySQL> Show Databases;
CentOS-7.5 build MySQL master-slave replication

slave server side:
[the root @ ~ the CentOS-2] #
[2-the CentOS the root @ ~] MySQL -uroot--p'Mysql.2020 # '# log slave
MySQL>
MySQL> Show Databases;
CentOS-7.5 build MySQL master-slave replication

Comparison Results: consistent master and slave ends before the verification data

2) create a master database and insert the data end
MySQL>
MySQL> Create Database db_1;
Query the OK,. 1 Row affected (0.00 sec)

mysql>
mysql> use db_1;
Database changed
mysql>
mysql> create table Student(
-> Sid varchar(10),
-> Sname nvarchar(10),
-> Sage datetime,
-> Ssex nvarchar(10)
-> );
Query OK, 0 rows affected (0.13 sec)

mysql>
mysql> desc Student;
CentOS-7.5 build MySQL master-slave replication
mysql>
mysql>
mysql> insert into Student values('01','张磊','1995-02-08','男');
Query OK, 1 row affected (0.01 sec)

mysql>
mysql> insert into Student values('02','李华','1995-06-11','男');
Query OK, 1 row affected (0.00 sec)

mysql>
mysql> insert into Student values('03','王青','1996-01-06','男');
Query OK, 1 row affected (0.01 sec)

mysql>
mysql> select * from Student;
CentOS-7.5 build MySQL master-slave replication

3) to check whether the slave terminal in the master data inserted
[the root @ ~ the CentOS-2] #
[2-the CentOS the root @ ~] # MySQL -uroot--p'Mysql.2020 '
MySQL>
MySQL> Show Databases;
CentOS-7.5 build MySQL master-slave replication
MySQL> db_1 use;
Reading Table Information for Completion of Table names and column
by You Turn OFF CAN GET to the this Feature -A with A Quicker Startup

Database changed
mysql>
mysql> show tables;
CentOS-7.5 build MySQL master-slave replication
mysql>
mysql> desc Student;
CentOS-7.5 build MySQL master-slave replication
mysql>
mysql> select * from Student;
CentOS-7.5 build MySQL master-slave replication

4) Remove the master-side data
MySQL>
MySQL> Database drop db_1;
Query the OK,. 1 Row affected (0.01 sec)

mysql>
mysql> show databases;
CentOS-7.5 build MySQL master-slave replication

5) to the slave end to see if there db_1 database
MySQL>
MySQL> Show Databases;
CentOS-7.5 build MySQL master-slave replication

Conclusion: The Proven results, MySQL-5.7 build successful master-slave synchronization

Guess you like

Origin blog.51cto.com/14783377/2485053