当前位置:网站首页>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 .
边栏推荐
- this指向问题,闭包以及递归
- 力扣SQL语句习题,错题记录
- Arduino+ze08-ch2o formaldehyde module, output formaldehyde content
- Hdu4496 d-city [concurrent search]
- Getting started for beginners: build your own blog with WordPress
- Slam overview Reading Note 6: slam research based on image semantics: application-oriented solutions for autonomous navigation of mobile robots 2020
- This points to problems, closures, and recursion
- log4j2 jdbc appender
- Dako held a meeting for the biological IPO: the annual revenue was 837million, and Wu Qingjun and his daughter were the actual controllers
- YOLOX改进之一:添加CBAM、SE、ECA注意力机制
猜你喜欢

Unity3D学习笔记10——纹理数组
![[training day3] delete [simulation]](/img/7b/217d4a9fa1426107eb7d6890dc9dc5.png)
[training day3] delete [simulation]

Airport cloud business sign analysis

【科普】精度和分辨率的区别与联系

Navicate reports an error access violation at address 00000000
![[training day4] anticipating [expected DP]](/img/66/35153a9aa77e348cae042990b55b1c.png)
[training day4] anticipating [expected DP]

MySQL advanced II. Logical architecture analysis

线程知识总结

this指向问题,闭包以及递归

Import the virtual machine officially made by Kali Linux into Oracle VirtualBox
随机推荐
基于招聘广告的岗位人才需求分析框架构建与实证研究
YOLOX改进之一:添加CBAM、SE、ECA注意力机制
Detoxify! After Harbin Institute of technology was disabled MATLAB, domestic industrial software fought back domineering
[training day3] section [greed] [two points]
力扣SQL语句习题,错题记录
进程间通信
[intensive reading of papers] grounded language image pre training (glip)
Interview eight part essay · TCP protocol
第3章业务功能开发(查看线索明细)
Navicate报错access violation at address 00000000
PROFINET simulator tutorial
The difference between [x for X in list_a if not np.isnan (x)] and [x if not np.isnan (x) else none for X in list_a]
Chapter 3 business function development (view clue details)
Slam overview Reading Note 7: visual and visual intangible slam: state of the art, classification, and empirical 2021
Good architecture is evolved, not designed
codeforces 1708E - DFS Trees
Pure C handwriting thread pool
Blocking queue
HDU4565 So Easy!【矩阵连乘】【推导】
[note] logistic regression