Mysql 5.7 docker master-slave replication architecture setup, mysqldocker

Source: Internet
Author: User
Tags docker cp

Mysql 5.7 docker master-slave replication architecture setup, mysqldocker
Environment version: MySQL: 5.7.13Docker: 1.11.2CentOS: 7.11. install two MySQL instances on two physical machines. The command is as follows:Docker pull mysql: 5.7.13docker run -- name anuo-mysql-p 3306: 3306-e MYSQL_ROOT_PASSWORD = qaz.00JK-d mysql: 5.7.132. Create a duplicate account on the master databaseGrant replication slave on *. * TO 'rep1' @ '192. 168.2.103 'identified BY 'qaz. 00JK '; the copy account is: rep1. The specified slave database IP address must be 192.168.2.103. The copy password is 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/root3.2 open my on the host. cnf: Add log-bin = mysql-binserver-id = 13.3 At the end of the [mysqld] node and upload the file to docker mysql to overwrite docker cp/root/my. cnf anuo-mysql:/etc/mysql/my. cnf3.4 restart mysql docker to make the configuration take effect docker restart anuo-mysql4. modify the configuration file of the slave DatabaseAs in step 3, the only difference is server-id = 2.5. Start the backup and execute the following command in the master database to make all tables in the master database read-only and non-writable, so as to achieve 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 DatabaseEasy operation with navicat for mysql7. 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 = '2017. 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 itemsMASTER_LOG_FILE and MASTER_LOG_POS are executed in the MASTER database: show master status; the command can obtain the corresponding fields: 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 DatabaseShow slave status; if the Slave_Io_State field is: Waiting for master to send event... it will succeed! ! !

Related Article

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.