How to use Docker to deploy MySQL 5.7 slave AMPs 8.0 master-slave cluster
This article mainly introduces how to use Docker to deploy MySQL 5.7 / 8.0 master-slave cluster, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.
Mirror version 5.7
1. Create an overlay network
Docker network create-driver overlay common-network-attachable
2. Edit two configuration files master.cnf and slave.cnf
! includedir / EtcUniverse mysqlAccorde conf.dUniqUBUBUR / etc/mysql/mysql.conf.d/ [mysqld] logmuri [mysqld] logmuri mysqlqlmae [mysqld] logMurray [mysqld]
3. Start 2 MYSQL:mysql-master and mysql-slave
Docker run-d\-- name mysql-master\-- network common-network\-e MYSQL_ROOT_PASSWORD=Passw0rd\-v `pwd` / master.cnf:/etc/mysql/my.cnf\-p 3306 MYSQL_ROOT_PASSWORD=Passw0rd 3306\-d mysql:5.7docker run-d\-name mysql-slave\-- network common-network\-e MYSQL_ROOT_PASSWORD=Passw0rd\-v `pwd` / slave.cnf:/etc/mysql/my.cnf\-p 3307 MYSQL_ROOT_PASSWORD=Passw0rd 3306\-d mysql:5.7
4. Add users from the library for replication
Docker run-it-- rm-- network common-network mysql mysql- hmysql-master-uroot-pPassw0rd\-e "CREATE USER 'repl'@'%' IDENTIFIED BY' password' REQUIRE SSL;"\-e "GRANT REPLICATION SLAVE ON *. * TO 'repl'@'%';"
5. Connect master & slave
Docker run-it-- rm-- network common-network mysql mysql- hmysql-slave-uroot-pPassw0rd\-e "CHANGE MASTER TO MASTER_HOST='mysql-master', MASTER_PORT=3306, MASTER_USER='repl', MASTER_PASSWORD='password', MASTER_AUTO_POSITION=1, MASTER_SSL=1;"\-e "START SLAVE;"
6. Verify slave status
Docker run-it-rm-network common-network mysql mysql- hmysql-slave-uroot-pPassw0rd-e "show slave status\ G"
The following states are normal:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
> deploy MySQL 8.0 cluster master & slave (for testing only)
Mirror version of mysql:8.0
1. Create an overlay network
Docker network create-driver overlay common-network-attachable
2. Start 2 MYSQL:mysql-master and mysql-slave
Docker run-d\-name mysql-master\-- network common-network\-e MYSQL_ROOT_PASSWORD=Passw0rd\-p 3306 MYSQL_ROOT_PASSWORD=Passw0rd 3306\-d mysql--default-authentication-plugin=mysql_native_passworddocker run-d\-name mysql-slave\-- network common-network\-e MYSQL_ROOT_PASSWORD=Passw0rd\-p 3307 MYSQL_ROOT_PASSWORD=Passw0rd 3306\-d mysql--default-authentication-plugin=mysql_native_password
3. Configure master & slave
Docker run-it-- rm-- network common-network mysql mysql- hmysql-master-uroot-pPassw0rd\-e "SET PERSIST server_id=1;"\-e "SET PERSIST_ONLY gtid_mode=ON;"\-e "SET PERSIST_ONLY enforce_gtid_consistency=true;"\-e "CREATE USER 'repl'@'%' IDENTIFIED BY' password' REQUIRE SSL;"\-e "GRANT REPLICATION SLAVE ON *. * TO 'repl'@'%' "docker run-it-- rm-- network common-network mysql mysql- hmysql-slave-uroot-pPassw0rd\-e" SET PERSIST server_id=2; "\-e" SET PERSIST_ONLY gtid_mode=ON; "\-e" SET PERSIST_ONLY enforce_gtid_consistency=true; "
4. Restart master & slave
Docker restart mysql-master mysql-slave
5. Connect master & slave
Docker run-it-- rm-- network common-network mysql mysql- hmysql-slave-uroot-pPassw0rd\-e "CHANGE MASTER TO MASTER_HOST='mysql-master', MASTER_PORT=3306, MASTER_USER='repl', MASTER_PASSWORD='password', MASTER_AUTO_POSITION=1, MASTER_SSL=1;"\-e "START SLAVE;"
6. Verify slave status
Docker run-it-rm-network common-network mysql mysql- hmysql-slave-uroot-pPassw0rd-e "show slave status\ G"
The following states are normal:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Verifying data synchronization
Create a database anoyi in master
Docker run-it-rm-network common-network mysql mysql- hmysql-master-uroot-pPassw0rd\-e "create database anoyi default character set utf8mb4 collate utf8mb4_general_ci;"
View the list of databases in slave
Docker run-it-rm-network common-network mysql mysql- hmysql-slave-uroot-pPassw0rd\-e "show databases "mysql: [Warning] Using a password on the command line interface can be insecure.+-+ | Database | +-+ | anoyi | | information_schema | | mysql | | performance_schema | | sys | +-+ Thank you for reading this article carefully. I hope the article "how to use Docker to deploy MySQL 5.7 / Slave Cluster" shared by the editor will be helpful to everyone. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!