MySQL 5.7 docker master-slave replication Architecture Tutorial _mysql

Source: Internet
Author: User
Tags docker cp docker run

Share MySQL 5.7 docker master-slave replication Architecture Tutorial for your reference, the specific contents are as follows

Environment version:
mysql:5.7.13
docker:1.11.2
centos:7.1

1. Install two MySQL on two physical machines first. Commands are as follows

Copy Code code as follows:
Docker Pull mysql:5.7.13
Docker run--name anuo-mysql-p 3306:3306-e mysql_root_password=qaz.00jk-d mysql:5.7.13

2. Create a replication account on the main library

Copy Code code as follows:
GRANT REPLICATION SLAVE on *.* to ' rep1 ' @ ' 192.168.2.103 ' identified by ' QAZ.00JK ';

Copy Account as: REP1
Specifies that the IP from the library must be: 192.168.2.103
Copy password is: QAZ.00JK

3. Modify the configuration file for the main library (Trouble, there should be more convenient way to modify)

3.1 First from Docker copy configuration file to host/root directory:

Docker CP Anuo-mysql:/etc/mysql/my.cnf/root

3.2 On the host open my.cnf, at the end of the [mysqld] node plus

Log-bin=mysql-bin
Server-id=1

3.3 Again upload this file to Docker MySQL cover

Docker cp/root/my.cnf ANUO-MYSQL:/ETC/MYSQL/MY.CNF

3.4 Restart the MySQL Docker for the configuration to take effect
Docker Restart Anuo-mysql

4. Modify the configuration file from the library

As with the third step, the only difference is
server-id=2

5. Start the backup, execute the following command in the main library so that all the tables in the main library can be read-only and cannot be written, so as to achieve the master-slave database data consistency

FLUSH TABLES with READ LOCK;

6. Database backup of the main library is restored from the library

Easy to operate with Navicat for MySQL

7. After restore from the library, release the main library read lock, so that the main library to restore Write permissions

Unlock tables;

8. Configure the Master library to connect from the library, executing from the library

Change MASTER to 
master_host= ' 192.168.2.108 ', 
master_port=3306, 
master_user= ' Rep1 ', 
master_ Password= ' Qaz.00jk ', 
master_log_file= ' mysql-bin.000002 ', 
master_log_pos=898;

The last two
Master_log_file and Master_log_pos
Execute in Main library: show Master STATUS; Commands can be obtained
The corresponding fields are File and Position

9. Start the slave thread synchronization from the library
START SLAVE;

10. View sync status from library
Show slave status;
If you see a slave_io_state field:

Waiting for Master to send event ...
That's a success!!!

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.