当前位置:网站首页>Docker builds MySQL master-slave replication
Docker builds MySQL master-slave replication
2022-07-24 11:02:00 【Scattered_ step】
First step : Create a new master server instance 3307
docker run -p 3307:3306 --name mysql-master \
-v /mydata/mysql-master/log:/var/log/mysql \
-v /mydata/mysql-master/data:/var/lib/mysql \
-v /mydata/mysql-master/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7
The second step : Get into /mydata/mysql-master/conf New under the directory my.cnf vim my.cnf
[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
The third step : Restart after modifying the configuration master example
docker restart mysql-master
Step four : Get into mysql-master Containers :
docker exec -it mysql-master /bin/bash
mysql -uroot -proot
Step five :master Create a data synchronization user in the container instance
CREATE USER 'slave'@'%' IDENTIFIED BY '123456';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'slave'@'%';
Step six : Create a new instance from the server container 3308
docker run -p 3308:3306 --name mysql-slave \
-v /mydata/mysql-slave/log:/var/log/mysql \
-v /mydata/mysql-slave/data:/var/lib/mysql \
-v /mydata/mysql-slave/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7
Step seven : Get into /mydata/mysql-slave/conf New under the directory my.cnf vim my.cnf
[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
Step eight : Restart after modifying the configuration slave example
docker restart mysql-slave
Step nine : View the master-slave synchronization status in the master database
show master status;
Step 10 : Get into mysql-slave Containers :
docker exec -it mysql-slave /bin/bash
mysql -uroot -proot
Step 11 : Configure master slave replication in the slave database
change master to master_host=' The host machine ip', master_user='slave', master_password='123456', master_port=3307, master_log_file='mall-mysql-bin.000001', master_log_pos=617, master_connect_retry=30;

aster_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
The twelfth step : View the master-slave synchronization status in the slave database
show slave status \G;

Thirteenth Step : Start master-slave synchronization in the slave database

The fourteenth step : Check the database status and find that it has been synchronized

The fifteenth step :
Master slave replication test
Host new library - Use the library - new table - insert data ,ok
Slave use library - View records ,ok
边栏推荐
- Qt程序最小化托盘后,再弹出个msgbox,点击确定后程序退出问题解决
- Distributed lock implementation scheme (glory collection version)
- Simply use MySQL index
- 二叉树基础知识概览
- Rtklib source code, RTK difference calculation, rtkpos and replos function process sorting
- 零基础学习CANoe Panel(3)—— 静态控件(Static Text , Group Box ,Picture Box)
- 向量化引擎对HTAP的价值与技术思考
- 简单使用 MySQL 索引
- QT create application tray and related functions
- cookie sessionStorage localStorage 区别
猜你喜欢

零基础学习CANoe Panel(5)——改变变量的值,控件图像也改变,这是怎么回事?

数据可视化-《白蛇2:青蛇劫起》(1)

How to gracefully realize idempotency and distributed current limiting of distributed interfaces (glory Collection Edition)

UVM——双向通信

Distributed transaction processing scheme big PK!

Download path of twincat3 versions

QT application prevents multiple opening, that is, single instance operation

小熊派学习——内核开发
![[personal summary] end of July 17, 2022](/img/56/8c69b171140ca38e16f0bbb7f344e3.jpg)
[personal summary] end of July 17, 2022

No one knows what ingredients tiktok's latest popular product pink sauce contains
随机推荐
1184. Distance between bus stops: simple simulation problem
In idea, system.getproperty ("user.dir") identifies the path of the module: the setting of the working directory
用 Signal Processing Toolbox 软件对数据进行滤波
Five best WordPress advertising plug-ins
Detailed explanation and example demonstration of Modbus RTU communication protocol
简单使用 MySQL 索引
[about Modelsim simulation] design and Simulation of 4-bit counter
UVM - two way communication
零基础学习CANoe Panel(9)—— 组合框(ComboBox)
Machine learning quiz (11) verification code recognition test - deep learning experiment using QT and tensorflow2
Windows virtual machine security reinforcement process steps, detailed description of windows setting security policy, detailed description of win7 setting IP security policy, windows setting firewall
N-tree, page_ Size, database strict mode modification, and the difference between delete and drop in the database
Mockito3.8 how to mock static methods (how to mock PageHelper)
【类、抽象与继承】
乘势而上,OceanBase推动数字支付精益增长
RS485 communication OSI model network layer
Zero basic learning canoe panel (7) -- file selection (pathdiaglog)
[white hat talks about web security] Chapter 1 my security world view
【白帽子讲Web安全】第一章 我的安全世界观
Qt应用程序防止多开,即单例运行