Mysql 5.7 docker master-slave replication architecture setup tutorial, mysqldocker

Source: Internet
Author: User
Tags docker cp docker run

Mysql 5.7 docker master-slave replication architecture setup tutorial, mysqldocker

Share the tutorial on building the mysql 5.7 docker master-slave replication architecture for your reference. The details are as follows:

Environment version:
MySQL: 5.7.13
Docker: 1.11.2
CentOS: 7.1

1. install two MySQL instances on two physical machines.The command is as follows:

Copy codeThe Code is 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 duplicate account on the master database

Copy codeThe Code is as follows: grant replication slave on *. * TO 'rep1' @ '192. 168.2.103 'identified BY 'qaz. 00JK ';
Duplicate account: rep1
The IP address of the specified slave database must be 192.168.2.103.
Copy password: qaz.00JK

3. modify the configuration file of the master database(Troublesome, there should be more convenient modification methods)

3.1 first copy the configuration file from docker to the host/root directory:

Docker cp anuo-mysql:/etc/mysql/my. cnf/root

3.2 open my. cnf on the host and add it at the end of the [mysqld] Node

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

3.3 upload the file to docker mysql to overwrite it

Docker cp/root/my. cnf anuo-mysql:/etc/mysql/my. cnf

3.4 restart mysql docker to make the configuration take effect
Docker restart anuo-mysql

4. modify the configuration file of the slave Database

Like step 3, the only difference is
Server-id = 2

5. Start backup,Run the following command on the master database to make all tables in the master database read-only and writable, so as to ensure data consistency between the master and slave databases.

Flush tables with read lock;

6. Back up the database of the master database in the slave Database

Easy operation with navicat for mysql

7. After the database is restored, the read lock of the master database is released, so that the write permission of the master database is restored.

Unlock tables;

8. Configure the slave database to connect to the master database and execute it on the slave database.

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;

Last two items
MASTER_LOG_FILE and MASTER_LOG_POS
Run the show master status command in the MASTER database to obtain
The corresponding fields are File and Position.

9. Start the slave thread in the slave database to start synchronization.
Start slave;

10. view the synchronization status in the slave Database
Show slave status;
If you see the Slave_Io_State field:

Waiting for master to send event...
That's it! ! !

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

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.