In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
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!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.