当前位置:网站首页>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 .
边栏推荐
- Lighting 5g in the lighthouse factory, Ningde era is the first to explore the way made in China
- JS什么是声明提前?函数与变量声明提前的先后顺序(执行上下文铺垫篇)
- 力扣SQL语句习题,错题记录
- np.arange()和 range()的用法及区别
- Positive mask, negative mask, wildcard
- watch VS watchEffect
- 面向不平衡数据的电子病历自动分类研究
- 大家最想要的,最全的C语言知识点总结,还不赶紧学习
- codeforces 1708E - DFS Trees
- Cognition -- classic of the road to success of hardware engineers
猜你喜欢

基于在线问诊记录的抑郁症病患群组划分与特征分析

基于招聘广告的岗位人才需求分析框架构建与实证研究

Cognition -- classic of the road to success of hardware engineers

Dako held a meeting for the biological IPO: the annual revenue was 837million, and Wu Qingjun and his daughter were the actual controllers

Airport cloud business sign analysis
![[training day4] anticipating [expected DP]](/img/66/35153a9aa77e348cae042990b55b1c.png)
[training day4] anticipating [expected DP]

【多线程的相关内容】

codeforces 1708E - DFS Trees

一篇文章看懂JS执行上下文

Windows10 installing SQL Server 2019
随机推荐
次小生成树【模板】
一篇文章看懂JS执行上下文
Understand JS execution context in an article
spark job 使用log4j appender 追加日志到本地文件或者mysql
HDU4496 D-City【并查集】
进程间通信
printf函数缓冲区问题
Zhishang technology IPO meeting: annual revenue of 600million, book value of accounts receivable of 270Million
架构——MVC的升华
Detoxify! After Harbin Institute of technology was disabled MATLAB, domestic industrial software fought back domineering
WPF visifire.charts4.6.1 tutorial with source code
Rtl8762dk environment construction (I)
Hard deduction SQL statement exercises, wrong question records
C语言基础练习题目
Navicate reports an error access violation at address 00000000
第3章业务功能开发(添加线索备注,自动刷新添加内容)
Group division and characteristic analysis of depression patients based on online consultation records
watch VS watchEffect
"Game engine light in light out" 4.1 unity shader and OpenGL shader
Printf function buffer problem