当前位置:网站首页>Docker advanced -mysql master-slave replication
Docker advanced -mysql master-slave replication
2022-07-26 01:10:00 【Little brother】
1、Mysql Master slave replication principle
Mysql Master slave replication principle
2、Mysql Master replication creation steps
2.1、 Create a new master server container instance 3307
docker run -p 3307:3306 --name mysql-master -v /temp/mysql/mysql-master/log:/var/log/mysql -v /temp/mysql/mysql-master/data:/var/lib/mysql -v /temp/mysql/mysql-master/conf:/etc/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7

2.2、 Get into /temp/mysql/mysql-master/conf New under the directory my.cnf
Lord my.cnf Profile contents
[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 .
expire_logs_days=7
## 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
2.3、 After revising my.cnf Restart after master example
docker restart mysql-master

2.4、 Get into mysql-master Containers
docker exec -it mysql-master /bin/bash
mysql -uroot -p

2.4、mysql-master Create a data synchronization user in the container instance
# Specify the user name as salve, The password for 123456 Users can access mysql-matser
CREATE USER 'slave'@ '%' IDENTIFIED BY 'root';
# Authorize this user
GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO 'slave'@'%';
2.5、 View the master-slave synchronization status in the master database
show master status;

3、Mysql Create steps from replication
3.1、 Create a new instance from the server container 3308
docker run -p 3308:3306 --name mysql-slave -v /temp/mysql/mysql-slave/log:/var/log/mysql -v /temp/mysql/mysql-slave/data:/var/lib/mysql -v /temp/mysql/mysql-slave/conf:/etc/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7


3.2、 Get into /temp/mysql/mysql-slave/conf New under the directory my.cnf
from my.cnf Profile contents
[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 Master 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 .
expire_logs_days=7
## 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
## 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
log_slave_updates=1
## slave Set to read only ( have super Except for users with permission )
read_only=1
3.3、 After revising my.cnf Restart after slave example
docker restart mysql-slave

3.4、 Get into mysql-slave Containers
docker exec -it mysql-slave /bin/bash
mysql -uroot -p

3.5、 Configure master slave replication in the slave database
change master to master_host=' Host the host ip', master_user='slave', master_password=' Lord mysql password ', master_port=3307, master_log_file='mall-mysql-bin.000001', master_log_pos=617,master_connect_retry=30;

mysql Description of master-slave copy parameters :

View host host ip

3.6、 View the master-slave synchronization status in the slave database
show slave status \G;

3.7、 Start master-slave synchronization in the slave database
start slave;


4、 Master slave replication test

边栏推荐
- Mmocr usage guide
- Jupyter changes the main interface and imports the dataset
- Gcdqueue encapsulation
- Lock upgrade: no lock, bias lock, lightweight lock, heavyweight lock
- RHCE之at和crontab命令详解及chrony部署
- Data is written into excel and filled with color
- Suddenly found an optimization artifact
- [software development specification III] [software version naming Specification]
- Open download! Alibaba Devops Practice Manual
- 什么是信息化?什么是数字化?这两者有什么联系和区别?
猜你喜欢

Redis数据结构详解,结合书本

【纪中】2022.7.16 1432.输油管道
![[RTOS training camp] learn C language from a higher perspective](/img/4c/bbbec489abb781a1de1e99bbf12c6f.png)
[RTOS training camp] learn C language from a higher perspective

NIO简易示例

Spine_ Adnexal skin

Inverse matrix block matrix
![[RTOS training camp] equipment subsystem, questions of evening students](/img/12/20fc69b5faf4c2d6dfaacde8142e33.jpg)
[RTOS training camp] equipment subsystem, questions of evening students

加载dll失败

iNFTnews | 假如这是元宇宙20年后的样子
![[RTOS training camp] ring buffer, at instruction, preview arrangement and evening class questions](/img/cb/de38e9f4186c4392ef8832659422ff.jpg)
[RTOS training camp] ring buffer, at instruction, preview arrangement and evening class questions
随机推荐
Suddenly found an optimization artifact
全国一半人跑长沙,长沙一半人跑哪?
IP地址能精确到哪步?动态IP及静态IP是什么?切换IP最常用的方法
matlab 移位操作基础
[Code] refers to the repeated number in the offer 03 array
Amin's confession
NLP introduction + practice: Chapter 4: using pytorch to manually realize linear regression
加载dll失败
How to copy and paste QT? (QClipboard)
Sqli-labs Less7
SQL的CASE WHEN
《暗黑破坏神:不朽》手游如何多开搬砖及新手入门搬砖攻略
[RTOS training camp] GPIO knowledge and preview arrangement + evening class questions
What if win11 cannot open its own anti-virus software? Win11's built-in anti-virus function cannot be turned on
The ultra comprehensive open source WinForm UI library meets all your desktop development needs!
How can MySQL just duplicate data?
中心对称的二进制模式CSLBP,matlab
[secsha concept] large and small end
The difference and application of in and exists in SQL statement
Fundamentals of MATLAB shift operation