当前位置:网站首页>Docekr learning - MySQL 8 master-slave replication setup deployment
Docekr learning - MySQL 8 master-slave replication setup deployment
2022-07-25 13:06:00 【Uh huh**】
List of articles
Master and slave copy build
# Download mirroring
docker pull mysql
# First step : Start master MySQL
docker run --name=mysql-master -p 3308:3306 -v /etc/localtime:/etc/localtim -v /www/server/mysql_master-slave/master/data:/var/lib/mysql -v /www/server/mysql_master-slave/master/log:/var/log/mysql -v /www/server/mysql_master-slave/master/conf:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=root --privileged=true -d mysql:latest
# The second step : Add configuration file /www/server/mysql_master-slave/master/conf/my.cnf == The contents are as follows
[mysqld]
## Set up server id, You need to be unique in the same LAN
server_id=101
## Specify the name of the database that does not need to be synchronized
binlog-ignore-db=mysql
## Turn on binary log function
log-bin=mall-mysql-bin
## Set the memory size of binary log ( Business )
binlog_cache_size=1M
## Set the binary log format to use (mixed,statement,row)
binlog_format=mixed
## Binary log expiration cleanup time . The default value is 0, Does not automatically clean up .
# Old edition 5 Configuration of == If it is 8 Remember to replace it with seconds , Otherwise I can't get in mysqld
#expire_logs_days=7
# new edition 8 Configuration of
binlog_expire_logs_seconds=604800
## Skip all errors encountered in master-slave replication or errors of the specified type , avoid slave End copy interrupt .
## Such as :1062 An error is a duplicate of some primary keys ,1032 The error is because the master-slave database data is inconsistent
slave_skip_errors=1062
# The third step : Restart master MySQL
docker restart mysql-master
# Step four : Lord MySQL Created in slave user == Make forever Navicat Or directly enter the container for operation
# Enter the main container mysql:docker exec -it mysql-master mysql -uroot -p
CREATE USER 'slave'@'%' IDENTIFIED BY '123456';
GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO 'slave'@'%';
SELECT plugin FROM `user` where user = 'slave';
# about mysql8 This step is particularly important , You need to modify the authorization plug-in , Otherwise, from MySQL There is no connection to the master MySQL Pull data synchronously
# If it is MySQL5 You don't need to run this statement
ALTER USER 'slave'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
# Step five : Start from MySQL
docker run --name=mysql-slave -p 3309:3306 -v /etc/localtime:/etc/localtim -v /www/server/mysql_master-slave/slave/data:/var/lib/mysql -v /www/server/mysql_master-slave/slave/log:/var/log/mysql -v /www/server/mysql_master-slave/slave/conf:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=root --privileged=true -d mysql:latest
# Step six : Add configuration file /www/server/mysql_master-slave/slave/conf/my.cnf == The contents are as follows
[mysqld]
## Set up server._id, You need to be unique in the same LAN
server_id=102
# Specify the name of the database that does not need to be synchronized
binlog-ignore-db=mysql
# Turn on binary log function , in preparation for Slave As an instance of another database Masterl When using
log-bin=mall-mysql-slave1-bin
# Set the memory size of binary log ( Business )
binlog_cache_size=1M
# Set the binary log format to use (mixed,statement,row)
binlog_format=mixed
# Binary log expiration cleanup time . The default value is 0, Does not automatically clean up .
# Old edition 5 Configuration of
#expire_logs_days=7
# new edition 8 Configuration of
binlog_expire_logs_seconds=604800
# Skip all errors encountered in master-slave replication or errors of the specified type , avoid slave End copy interrupt .
# Such as :1062 An error is a duplicate of some primary keys ,1032 The error is because the master-slave database data is inconsistent
# Old edition 5 Configuration of
#slave_skip_errors=1062
# new edition 8 Configuration of
replica_skip_errors=1062
#relay_log Configure relay logs
relay_log=mall-mysql-relay-bin
#log_slave_.updates Express slave Write the copy event to your own binary log
# Old edition 5 Configuration of
#log_slave_updates=1
# new edition 8 Configuration of
log_replica_updates=1
##slave Set to read only ( have super Except for users with permission )
read_only=1
# Step seven : Restart from MySQL
docker restart mysql-slave
# Step eight : Look at the main MySQL Of master state
docker exec -it mysql-master mysql -uroot -proot
show master status;
# Step nine : Enter from mysql == Set master MySQL Relevant information
docker exec -it mysql-slave mysql -uroot -proot
# master_log_file、master_log_pos Taken from the Lord MySQL Of show master status Information
# Fill in the main MySQL The port of 、ip Etc
change master to master_host='192.168.80.128',master_user='slave',master_password='123456',master_port=3308,master_log_file='mall-mysql-bin.000002',master_log_pos=156,master_connect_retry=30;
# Step 10 : View from the MySQL Of slave Related information == from MySQL Run in
# It is found that the synchronization switch has not been turned on
show slave status;
# Step 11 : Start from the library and turn on the switch to pull the main library -- from MySQL Run in
start slave;
# The twelfth step : Check whether the synchronization switch of the slave library is on
show slave status;
# Thirteenth Step : Data synchronization test == Be accomplished
Lord MySQL: Chuang Ku 、 Table creation 、 The new data
from MySQL: Check whether the data is synchronized

Solve the problems encountered in master-slave replication
MY-010095 - Boot failure
2022-07-21 05:10:09+00:00 [Note] [Entrypoint]: Starting temporary server
mysqld: Error on realpath() on '/var/lib/mysql-files' (Error 2 - No such file or directory)
2022-07-21T05:10:09.822859Z 0 [ERROR] [MY-010095] [Server] Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/lib/mysql-files
2022-07-21 05:10:09+00:00 [ERROR] [Entrypoint]: Unable to start server.

Solution - Change run Mapping configuration of configuration file
// Original startup configuration == Encounter the above startup error
docker run --name=mysql-master -p 3308:3306 -v /etc/localtime:/etc/localtim -v /www/server/mysql_master-slave/master/data:/var/lib/mysql -v /www/server/mysql_master-slave/master/log:/var/log/mysql -v /www/server/mysql_master-slave/master/conf:/etc/mysql -e MYSQL_ROOT_PASSWORD=root --privileged=true -d mysql:latest
// Start the configuration after correction == Can be started normally == Change mysql Mapping directory
docker run --name=mysql-master -p 3308:3306 -v /etc/localtime:/etc/localtim -v /www/server/mysql_master-slave/master/data:/var/lib/mysql -v /www/server/mysql_master-slave/master/log:/var/log/mysql -v /www/server/mysql_master-slave/master/conf:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=root --privileged=true -d mysql:latest
Failed to connect from the library to the main library - Not IP、 Account and password problems
Last_IO_Error: error connecting to master 'slave@192.168.80.128:3308' - retry-time: 30 retries: 17 message: Authentication plugin 'caching_sha2_password' reported error: Authentication requires secure connection.
Run from the machine :show slave status
Solution
-- In the main MySQL Run the following in the machine SQL == Modify the authorization plug-in
-- There is no need to restart after modification Lord MySQL、 from MySQL
SELECT plugin FROM `user` where user = 'slave';
ALTER USER 'slave'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
Run from the machine :show slave status
边栏推荐
- 【历史上的今天】7 月 25 日:IBM 获得了第一项专利;Verizon 收购雅虎;亚马逊发布 Fire Phone
- LeetCode 1184. 公交站间的距离
- State mode
- 【视频】马尔可夫链原理可视化解释与R语言区制转换MRS实例|数据分享
- Atcoder beginer contest 261e / / bitwise thinking + DP
- Docekr学习 - MySQL8主从复制搭建部署
- 想要白嫖正则大全是吧?这一次给你个够!
- 【AI4Code】《CodeBERT: A Pre-Trained Model for Programming and Natural Languages》 EMNLP 2020
- Word style and multi-level list setting skills (II)
- Perf performance debugging
猜你喜欢

cv2.resize函数报错:error: (-215:Assertion failed) func != 0 in function ‘cv::hal::resize‘

【AI4Code】《Contrastive Code Representation Learning》 (EMNLP 2021)

word样式和多级列表设置技巧(二)

【Rust】引用和借用,字符串切片 (slice) 类型 (&str)——Rust语言基础12

Vim技巧:永远显示行号

如何用因果推断和实验驱动用户增长? | 7月28日TF67

web安全入门-UDP测试与防御

跌荡的人生

Mid 2022 review | latest progress of large model technology Lanzhou Technology

Zero basic learning canoe panel (15) -- CAPL output view
随机推荐
[300 opencv routines] 239. accurate positioning of Harris corner detection (cornersubpix)
SSTI template injection vulnerability summary [bjdctf2020]cookie is so stable
Microsoft proposed CodeT: a new SOTA for code generation, with 20 points of performance improvement
Shell Basics (exit control, input and output, etc.)
Zero basic learning canoe panel (13) -- trackbar
[problem solving] ibatis.binding BindingException: Type interface xxDao is not known to the MapperRegistry.
Shell常用脚本:获取网卡IP地址
公安部:国际社会普遍认为中国是世界上最安全的国家之一
Chapter5 : Deep Learning and Computational Chemistry
Chapter5 : Deep Learning and Computational Chemistry
OAuth,JWT ,OIDC你们搞得我好乱啊
Deep learning MEMC framing paper list
《富兰克林自传》修身
【视频】马尔可夫链原理可视化解释与R语言区制转换MRS实例|数据分享
[problem solving] org.apache.ibatis.exceptions PersistenceException: Error building SqlSession. 1-byte word of UTF-8 sequence
[operation and maintenance, implementation of high-quality products] interview skills for technical positions with a monthly salary of 10k+
LeetCode 1184. 公交站间的距离
Leetcode 0133. clone diagram
shell基础知识(退出控制、输入输出等)
Kyligence was selected into Gartner 2022 data management technology maturity curve report