当前位置:网站首页>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
- 线程知识总结
- 基于企业知识图谱的企业关联关系挖掘
- 解气!哈工大被禁用MATLAB后,国产工业软件霸气回击
- 进程间通信
- Pure C handwriting thread pool
- Detoxify! After Harbin Institute of technology was disabled MATLAB, domestic industrial software fought back domineering
- log4j2 jdbc appender
- Excellent basic methods of URL parsing using C language
- JS what is declaration in advance? The order of function and variable declaration in advance (the foreshadowing of execution context)
猜你喜欢

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

Schematic diagram of C measuring tool

大家最想要的,最全的C语言知识点总结,还不赶紧学习

592. Fraction addition and subtraction

面试八股文之·TCP协议

机场云商sign解析

PROFINET 模拟器使用教程

Weice biological IPO meeting: annual revenue of 1.26 billion Ruihong investment and Yaohe medicine are shareholders

Slam overview Reading Note 6: slam research based on image semantics: application-oriented solutions for autonomous navigation of mobile robots 2020

万字详解 Google Play 上架应用标准包格式 AAB
随机推荐
Secondary spanning tree [template]
spark job 使用log4j appender 追加日志到本地文件或者mysql
YOLOX改进之一:添加CBAM、SE、ECA注意力机制
PROFINET simulator tutorial
Electronic bidding procurement mall system: optimize traditional procurement business and speed up enterprise digital upgrading
Cultural tourism and data collection | travel to Yunnan in an artistic way
Recursive method to realize the greatest common divisor
Good architecture is evolved, not designed
Slam overview Reading Note 6: slam research based on image semantics: application-oriented solutions for autonomous navigation of mobile robots 2020
【笔记】逻辑斯蒂回归
Chapter 3 business function development (add clues and remarks, and automatically refresh the added content)
Negative ring
Why does script file 'd:\anaconda3\envs\pad appear_ env\Scripts\pip-script. py‘ is not present.
Simple encapsulation steps of request data request of uniapp
np. Usage and difference of range() and range()
How to view revenue and expenditure by bookkeeping software
Navicate reports an error access violation at address 00000000
Shell编程规范与变量
Chapter 3 business function development (view clue details)
开源版思源怎么私有部署