当前位置:网站首页>Using docker for MySQL 8.0 master-slave configuration
Using docker for MySQL 8.0 master-slave configuration
2022-07-05 12:36:00 【just4you】
MySQL Single machine configuration
Pull & Start the container
docker run -d \
--name mysql \
--privileged=true \
-v /usr/local/mysql/data:/var/lib/mysql \
-v /usr/local/mysql/conf:/etc/mysql/ \
-v /usr/local/mysql/log:/var/log/mysql \
-v /usr/local/mysql/mysql-files:/var/lib/mysql-files/ \
-e MYSQL_ROOT_PASSWORD=123456 \
-p 3306:3306 \
mysql
The latest version pulled by default is mysql8
docker Mirror image :https://hub.docker.com/_/mysql?tab=tags
To configure mysql
stay /usr/local/mysq/conf Add files to directory :my.cnf
[client]
default-character-set=utf8mb4
[mysqld]
# Specify the authentication plug-in
authentication_policy=mysql_native_password
- mysql8 The default encoding format of the server :utf8mb4, So the character encoding can not be set .
- Authentication plug-in : stay mysql5.7 The plug-in in is "mysql_navtive_password", And in the mysql8 The plug-in used is " caching_sha2_password", To avoid problems when the client connects , So you need to set it up .
Restart Mysql
docker restart mysql
Into the container
docker exec -it mysql bin/bash
Entering the container MySQL
mysql -uroot -p123456
MySQL Master slave configuration
MySQL Master
Docker Set up
Specify the host port as :13306
docker run -d \
--name mysql-master-13306 \
--privileged=true \
-v /usr/local/mysql-master/data:/var/lib/mysql \
-v /usr/local/mysql-master/conf:/etc/mysql/ \
-v /usr/local/mysql-master/log:/var/log/mysql \
-v /usr/local/mysql-master/mysql-files:/var/lib/mysql-files/ \
-e MYSQL_ROOT_PASSWORD=123456 \
-p 13306:3306 \
mysql
The configuration file
stay /usr/local/mysql-master/conf Add profile to :my.cnf
[client]
default-character-set=utf8mb4
[mysqld]
## serverId, It's the only one in the LAN
server_id=01
## Turn on binary log function
log-bin=ms-mysql-bin
## Specify the name of the database that does not need to be synchronized , More than one... Can be specified
binlog-ignore-db=mysql
binlog-ignore-db=sys
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
## Specify a synchronized database , More than one... Can be specified
binlog-do-db=db01
binlog-do-db=db02
## Binary log uses memory size ( Business )
binlog_cache_size=1M
## Binary log format (mixed, statement,row)
# statement: Add a write operation statement to binlog, And then in slave The machine is running . shortcoming : There are now() when , It will cause data inconsistency
# row: Record the changes in each line , And then in slave Machine update . shortcoming : When updating in batch , Will be in slave The machine performs a lot update
# mixed: It's similar now() This kind of function will cause data inconsistency , Use row Pattern , Otherwise, use statement Pattern .
binlog_format=mixed
## Binary log expiration cleanup time , Default 2592000 second (30 God ),604800 second (7 God )
binlog_expire_logs_seconds=604800
## Skip all errors encountered in master-slave replication or errors of the specified type , avoid slave Replication interrupt
replica_skip_errors=1062
# Specify the authentication plug-in
authentication_policy=mysql_native_password
restart Master
docker restart mysql-master-13306
Add backup users
Get into MySQL
CREATE USER 'slave'@'%' identified by 'backup';
GRANT REPLICATION SLAVE ON *.* TO 'slave'@'%';
FLUSH PRIVILEGES;
stay mysql5.7 in , You can use a statement to create users and assign :GRANT REPLICATION SLAVE ON . TO ‘slave’@’%’ IDENTIFIED BY ‘backup’;
stay mysql8 It seems that there will be an error in , Separate the user creation and empowerment statements .
see & Record Master state
mysql> show master status \G;
*************************** 1. row ***************************
File: ms-mysql-bin.000003
Position: 1535
Binlog_Do_DB:
Binlog_Ignore_DB: mysql
Executed_Gtid_Set:
1 row in set (0.01 sec)
a key :
- File: ms-mysql-bin.000003
- Position: 1535
MySQL Slave
Docker Set up
Specify the host port as :13307
docker run -d \
--name mysql-slave-13307 \
--privileged=true \
-v /usr/local/mysql-slave/data:/var/lib/mysql \
-v /usr/local/mysql-slave/conf:/etc/mysql/ \
-v /usr/local/mysql-slave/log:/var/log/mysql \
-v /usr/local/mysql-slave/mysql-files:/var/lib/mysql-files/ \
-e MYSQL_ROOT_PASSWORD=123456 \
-p 13307:3306 \
mysql
The configuration file
stay /usr/local/mysql-slave/conf Add profile to :my.cnf
[client]
default-character-set=utf8mb4
[mysqld]
## serverId, It's the only one in the LAN
server_id=11
## Specify the name of the database that does not need to be synchronized
binlog-ignore-db=mysql
## Turn on binary log function
log-bin=ms-mysql-slave11-bin
## Binary log uses memory size ( Business )
binlog_cache_size=1M
## Binary log format (mixed, statement,row)
binlog_format=mixed
## Binary log expiration cleanup time , Default 2592000 second (30 God ),604800 second (7 God )
binlog_expire_logs_seconds=604800
## Skip all errors encountered in master-slave replication or errors of the specified type , avoid slave Replication interrupt
replica_skip_errors=1062
## relay_log To configure slave The trunk log of
relay_log=ms-mysql-relay-bin
## Write the copy event to your own binary log
log_slave_updates=1
## Set to read only (super Except for authorized users )
read_only=1
# Specify the authentication plug-in
authentication_policy=mysql_native_password
restart slave Containers
docker restart mysql-slave-13307
see slave state
Get into slave
show slave status;
here , Usually there is no information .
take slave Connect to master
# stop it slave
stop slave;
# If you have done master-slave replication , You may also need to execute the following commands
## reset master;
# Connect to master
# master_log_file and master_log_pos The value of reference master Results of machine status query :
change master to master_host='192.168.10.121', master_user='slave', master_password='backup', master_port=13306,master_log_file='ms-mysql-bin.000003',master_log_pos=1535,master_connect_retry=30;
# start-up slave
start slave;
Parameter description :
- master_host: master machine IP, That's the host IP
- master_port: master port ,docker When the configuration ,master External port
- master_user: Account used for synchronization
- master_password: Password for synchronization
- master_log_file: Appoint slave To copy master Data log file
- master_log_pos: Specify where to start copying
- master_connect_retry: When the connection fails , Retry interval , Company : second
see slave state
show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for source to send event
Master_Host: 192.168.10.121
Master_User: slave
Master_Port: 13306
Connect_Retry: 30
Master_Log_File: ms-mysql-bin.000003
Read_Master_Log_Pos: 828
Relay_Log_File: ms-mysql-relay-bin.000002
Relay_Log_Pos: 327
Relay_Master_Log_File: ms-mysql-bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
..........
a key :
- Slave_IO_Running: Yes
- Slave_SQL_Running: Yes
When both values are “Yes” when , Description connection successful , Can be found in Master Data operation on the machine , And then, in slave The machine sees the effect of data synchronization .
other
If you inquire slave In the state of ,Slave_IO_Running The value of has always been Connecting, It may be the problem of account password or permission , Generally, you can see the prompt below , for example :
Last_IO_Error: error connecting to master '[email protected]:13306' - retry-time: 30 retries: 1 message: Authentication plugin 'caching_sha2_password' reported error: Authentication requires secure connection.
Adjust according to the prompt .
边栏推荐
- Want to ask, how to choose a securities firm? Is it safe to open an account online?
- JDBC -- extract JDBC tool classes
- UNIX socket advanced learning diary -ipv4-ipv6 interoperability
- 16 channel water lamp experiment based on Proteus (assembly language)
- 强化学习-学习笔记3 | 策略学习
- Making and using the cutting tool of TTF font library
- One article tells the latest and complete learning materials of flutter
- How to design an interface?
- Learning items
- Distributed solution - Comprehensive decryption of distributed task scheduling platform - xxljob scheduling center cluster
猜你喜欢
Pytoch loads the initialization V3 pre training model and reports an error
MySQL splits strings for conditional queries
Matlab boundarymask function (find the boundary of the divided area)
What is digital existence? Digital transformation starts with digital existence
mysql拆分字符串做条件查询
Matlab label2idx function (convert the label matrix into a cell array with linear index)
Preliminary exploration of basic knowledge of MySQL
Average lookup length when hash table lookup fails
Constructing expression binary tree with prefix expression
NPM install reports an error
随机推荐
Constructing expression binary tree with prefix expression
Learning JVM garbage collection 06 - memory set and card table (hotspot)
Introduction to GNN
[figure neural network] GNN from entry to mastery
想问问,如何选择券商?在线开户是很安全么?
Resnet+attention project complete code learning
Storage Basics
图像超分实验:SRCNN/FSRCNN
Tabbar configuration at the bottom of wechat applet
MySQL data table operation DDL & data type
The relationship between the size change of characteristic graph and various parameters before and after DL convolution operation
Pytoch uses torchnet Classerrormeter in meter
A new WiFi option for smart home -- the application of simplewifi in wireless smart home
Take you two minutes to quickly master the route and navigation of flutter
GPS數據格式轉換[通俗易懂]
ZABBIX ODBC database monitoring
Pytoch through datasets Imagefolder loads datasets directly from files
MySQL trigger
ZABBIX agent2 monitors mongodb templates and configuration operations
Solve the error 1045 of Navicat creating local connection -access denied for user [email protected] (using password