当前位置:网站首页>Docker practical experience: deploy mysql8 master-slave replication on docker
Docker practical experience: deploy mysql8 master-slave replication on docker
2022-07-27 14:29:00 【m0_ sixty-seven million three hundred and ninety-four thousand 】

List of articles
- Environmental preparation
- Easy version installation
- To configure MySQL Master slave copy
- establish bridge Network and specify IP Section
- Create data and configuration storage directory
- Prepare the configuration file
- Start database
- Remote access configuration ( Master-slave )
- The main library creates a copy user
- see master The state of the machine
- From library settings master Information about
- Enable master-slave replication
Environmental preparation
Need one MySQL8 Version of MySQL, Because I haven't used it personally mysql5, I don't know whether there will be some characteristic deviation between the two .
By default, your environment is the same as mine .
Easy version installation
Just install one first MySQL, If you are the master and slave, many details will be mixed together .
docker run -d -p 3306:3306 --privileged=true -v /mysql/log:/var/log/mysql -v /mysql/data:/var/lib/mysql -v /mysql/conf:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=123456 --name mysql mysql
Here are the parameters to introduce :
-p: Specify the internal and external port mapping , The virtual machine is external ,docker The container is inner , The one written in front is the external port , The following is the internal port . because MySQL The port itself is 3306, In order not to confuse you , My external port is not set to 3306.
-v: Specify the internal and external storage volume mapping ,Docker practical experience ( 3、 ... and ) That's what I'm talking about .
-e: Pass parameters to the inside of the container , Eventually it will be MySQL To receive . About this -e In fact, I haven't studied one of its trends .
Such a simple MySQL You can move .
Set the password
Without a password , I'm not sure if I can still get in the second login .
Uncertainty means that you can get in , Maybe I can't get in .
So it's safer for us to set a password by ourselves .
mysql> use mysql
mysql> update user set authentication_string='123456' where user='root' and host='localhost';
mysql> flush privileges;
Don't comment .
Now this MySQL You can move , Consider deleting , Let's start from copying .
If you want to keep it :
modify my.cnf, Synchronize to via data volume MySQL:
cd /mysql/conf
vim my.cnf
Insert the following :
[client]
default_character_set=utf8
[mysqld]
collation_server = utf8_general_ci
character_set_server = utf8
restart MySQL:
docker restart mysql
docker exec -it mysql bash
To configure MySQL Master slave copy
establish bridge Network and specify IP Section
docker network create --driver bridge mysql-master-slave
mysql The default number of connections is not enough
set global max_connections=500;
set global mysqlx_max_connections=500;
Create data and configuration storage directory
# Create the main database data storage directory
mkdir -p /home/docker/mysql/master/data
# Create the main library configuration storage directory
mkdir -p /home/docker/mysql/master/conf
# Create a slave Library 1 Data storage directory
mkdir -p /home/docker/mysql/slave1/data
# Create a slave Library 1 Configuration storage directory
mkdir -p /home/docker/mysql/slave1/conf
Prepare the configuration file
Master database
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
secure-file-priv= NULL
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# The server is unique ID, The default is 1
server-id=10
# Enable binary logging
log-bin=mysql-bin
# maximum connection
max_connections=10000
# Set the default time zone
default-time_zone='+8:00'
# 0: Case sensitive
# 1: Case insensitive
lower_case_table_names=1
!includedir /etc/mysql/conf.d/
From database
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
secure-file-priv= NULL
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# The server is unique ID, The default is 1
server-id=11
# Enable binary logging
log-bin=mysql-bin
# maximum connection
max_connections=10000
# Set the default time zone
default-time_zone='+8:00'
# 0: Case sensitive
# 1: Case insensitive
lower_case_table_names=1
!includedir /etc/mysql/conf.d/
Start database
Start the master database
If the above completely follow my steps , There is no need to change the parameters of the command here .
docker run -d -p 3316:3306 --name mysql_master --restart=always --network mysql-master-slave -v /home/docker/mysql/master/data:/var/lib/mysql -v /home/docker/mysql/master/conf/my.cnf:/etc/mysql/my.cnf -e MYSQL_ROOT_PASSWORD=123456 mysql
Start from database
docker run -d -p 3326:3306 --name mysql_slave1 --restart=always --network mysql-master-slave -v /home/docker/mysql/slave1/data:/var/lib/mysql -v /home/docker/mysql/slave1/conf/my.cnf:/etc/mysql/my.cnf -e MYSQL_ROOT_PASSWORD=123456 mysql
Remote access configuration ( Master-slave )
# In the container mysql_master Open a terminal in interactive mode
docker exec -it mysql_master /bin/bash
# In the container mysql_slave1 Open a terminal in interactive mode
docker exec -it mysql_slave1 /bin/bash
# mysql Sign in
mysql -u root -p
# Give remote users all permissions on all tables
GRANT ALL ON *.* TO 'root'@'%';
# Change encryption rules
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;
# The remote access
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
# Refresh the permissions
flush privileges;
The main library creates a copy user
CREATE USER 'woniu'@'%' IDENTIFIED WITH mysql_native_password BY 'woniu123456';
GRANT REPLICATION SLAVE ON *.* TO 'woniu'@'%';
flush privileges;
see master The state of the machine
SHOW MASTER STATUS;

From library settings master Information about
If you follow my steps completely , Here you need to fill in your own host ip、 And the two data shown in the figure above .
change master to master_host='192.168.190.133', master_user='woniu', master_password='woniu123456', master_port=3316, master_log_file='mysql-bin.000003', master_log_pos=2838, master_connect_retry=30;
Parameter interpretation :
master_host: The main database IP Address ;
master_port: The running port of the primary database ;
master_user: A user account created in the master database to synchronize data ;
master_password: The user password created in the master database for synchronizing data ;
master_log_file: Specify the log file to copy data from the database , By looking at the status of the master data , obtain File Parameters ;
master_log_pos: Specify where to start copying data from the database , By looking at the status of the master data , obtain Position Parameters ;
master_connect_retry: The connection failed and the time interval between retries , The unit is in seconds .
Enable master-slave replication
# Start syncing
start slave;
# sync
show slave status ;

If it works , Circle out all the places yes、
If you fail , The log will be displayed :
Can own Baidu , But what Baidu comes out doesn't necessarily apply to us , After all, we are docker The upper part , There is little information available .
Rely on experience .
边栏推荐
- 10 practical uses of NFT
- log4j2 jdbc appender
- SLAM综述阅读笔记七:Visual and Visual-Inertial SLAM: State of the Art, Classification,and Experimental 2021
- c语言分层理解(c语言数组)
- Chapter 3 business function development (add clues and remarks, and automatically refresh the added content)
- 大家最想要的,最全的C语言知识点总结,还不赶紧学习
- 融合迁移学习与文本增强的中文成语隐喻知识识别与关联研究
- Slam overview Reading Note 4: a survey on deep learning for localization and mapping: towards the age of spatial 2020
- [training day4] card game [greed]
- Hdu4496 d-city [concurrent search]
猜你喜欢

One of yolox improvements: add CBAM, Se, ECA attention mechanism

进程间通信

架构——MVC的升华

基于预训练模型的多标签专利分类研究

Lighting 5g in the lighthouse factory, Ningde era is the first to explore the way made in China

Slam overview Reading Note 4: a survey on deep learning for localization and mapping: towards the age of spatial 2020
![[note] logistic regression](/img/2b/07cc3c26b1b34fbf2f09edaa33668e.jpg)
[note] logistic regression

融合迁移学习与文本增强的中文成语隐喻知识识别与关联研究

codeforces 1708E - DFS Trees

This points to problems, closures, and recursion
随机推荐
Unity3d learning note 10 - texture array
[luogu_p4820] [national training team] stack [mathematics] [physics] [harmonic progression]
【科普】精度和分辨率的区别与联系
codeforces 1708E - DFS Trees
GoPro access - control and preview GoPro according to GoPro official document /demo
Chapter 3 business function development (view clue details)
Hard deduction SQL statement exercises, wrong question records
Understand JS execution context in an article
[training day4] card game [greed]
Excellent basic methods of URL parsing using C language
Advanced MySQL III. storage engine
printf函数缓冲区问题
va_ List usage summary
JS 疫情宅在家,学习不能停,七千字长文助你彻底弄懂原型与原型链
Alibaba's latest equity exposure: Softbank holds 23.9% and caichongxin holds 1.4%
在Oracle VirtualBox中导入Kali Linux官方制作的虚拟机
Lighting 5g in the lighthouse factory, Ningde era is the first to explore the way made in China
Schematic diagram of C measuring tool
文献翻译__基于自适应全变差L1正则化的椒盐图像去噪
this指向问题,闭包以及递归