Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deploy MySQL8 GTID-based Master-Slave replication under docker

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces how to deploy MySQL8 master-slave replication based on GTID under docker. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

Install docker

# yum install docker

Add docker Image Warehouse

# vim / etc/docker/daemon.json

{

"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]"

}

Pull mysql image

* # docker pull mysql

Create a mysql container

# docker run-dit-- name lisamysql001-p 33307 MYSQLROOTPASSWORD=123456 mysql 3307-e MYSQLROOTPASSWORD=123456 mysql

# docker run-dit-- name lisamysql002-p 33308 MYSQLROOTPASSWORD=123456 mysql 3308-e MYSQLROOTPASSWORD=123456 mysql

Enter the mysql container

# docker exec-it lisamysql001 / bin/bash

# docker exec-it lisamysql002 / bin/bash

Log in to mysql in the mysql container, but it's still the mysql8.0 version. It smells good!

Let's go to the container to deploy GTID-based master-slave replication:

Container lisa_mysql001 is the master library and lisa_mysql002 is the slave library

Go to the main library (lisa_mysql001) to install vim for the docker container (it is convenient for me to modify the my.cnf file)

# docker exec-it lisa_mysql001 / bin/bash

# apt-get update

# apt-get install vim-y

Install the package for ifconfig and check the container IP address

# apt-get install net-tools-y

Install the ping command

# apt-get install inetutils-ping-y

The IP address of the main library (lisa_mysql001) is 172.17.0.2

Configure the my.cnf of the main library and add the following

# cat / etc/mysql/my.cnf

Server-id=001

Gtid-mode=on

Enforce-gtid-consistency=on

Log_bin = binlog

After modifying the configuration file of the main library, exit the mysql container and restart mysql

* # docker restart lisamysql001

Establish a synchronization account for the slave database

# mysql-uroot-p123456

Mysql > create user 'repl'@'172.17.0.%' identified by' 1225119'

Mysql > grant replication slave on. To 'repl'@'172.17.0.%'

Mysql > flush privileges

Check the uuid and status of the main library

Mysql > show global variables like'% uuid%'

After the slave library is successfully configured, test whether the master-slave replication can be synchronized.

Slave library configuration

# docker exec-it lisamysql002 / bin/bash

# apt-get update

# apt-get install vim-y

Install the ifconfig command to view the container IP address

# apt-get install net-tools-y

Install the ping command

# apt-get install inetutils-ping-y

The IP address of the slave library (lisa_mysql001) is 172.17.0.3

Test whether you can communicate with the main library

# ping 172.17.0.2

To configure the my.cnf of the slave library, add the following

Server-id=002

Gtid-mode=on

Enforce-gtid-consistency=on

Log-slave-updates = on

After modifying the configuration file of the slave library, exit the mysql container and restart mysql

* # docker restart lisamysql002

Test whether the account we set up in the master database can log in from the slave database.

* # mysql-urepl-h272.17.0.2-p

Configure the slave library to specify the master library

Mysql > change master to master_host='172.17.0.2',master_user='repl',master_password='1225119'

Mysql > start slave

Mysql > show slave status\ G

After the main library has built a library named songlisha, it is accepted from the library.

On how to deploy MySQL8 under docker GTID-based master-slave replication is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report