当前位置:网站首页>Docker MySQL master-slave backup
Docker MySQL master-slave backup
2022-04-23 11:27:00 【Oaa114 dragon boy】
1. download mysql:5.7 Mirror image
docker pull mysql:5.7
2. Create mount directory
vi mk.sh
mkdir -p install /root/mysqlms/data
mkdir -p install /root/mysqlms/conf.d
mkdir -p install /root/mysqlms/mysql-files
mkdir -p install /root/mysqlsl/data
mkdir -p install /root/mysqlsl/conf.d
mkdir -p install /root/mysqlsl/mysql-files
./mk.sh
3. Create the master server
Create the main container
docker run --name sqlms -p 3306:3306 -d -v /root/mysqlms/data:/var/lib/mysql/ -v /root/mysqlms/mysql-files:/var/lib/mysql-files/ -v /root/mysqlms/conf.d:/etc/mysql/conf.d/ -e MYSQL_ROOT_PASSWORD=root mysql:5.7
Enter the main container and place my.cnf Delete
docker exec -it sqlms bin/bash
rm -rf my.cnf
exit
Exit the container
Configure the master server in the host
Go to the mount Directory
cd /root/sqlms/conf.d
Create a mysql The configuration file
vi my.cnf
# Turn on bin-log Log and give a id
[mysqld]
server-id=1
log-bin=mysql-bin
Then enter the main container to my.cnf Move to the original directory
mv my.cnf /etc/mysql/
docker restart sqlms
Create from service container
Create slave server
docker run --name sqlsl -p 3307:3306 -d -v /root/mysqlsl/data:/var/lib/mysql/ -v /root/mysqlsl/mysql-files:/var/lib/mysql-files/ -v /root/mysqlsl/conf.d:/etc/mysql/conf.d/ -e MYSQL_ROOT_PASSWORD=root mysql:5.7
Repeat the operation of the main service container until mysql The configuration file
Change from mysql The configuration file
Go to the mount Directory
cd /root/sqlms/conf.d
Generate configuration files
vi my.cnf
[mysqld]
server-id=2
log-bin=mysql-slave-bin
relay_log=edu-mysql-relay-bin
Restart the service
docker restart sqlsl
After the preparation phase, start the formal operation
Main service container operation
Enter the main container and start mysql
docker exec -it sqlms bin/bash
mysql -uroot -proot
Enter at the command line
CREATE USER 'slave'@'%' IDENTIFIED BY '123456';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'slave'@'%';
Create a slave The user is authorized to read and write any file , Used for master-slave backup data
show master status;

Need to be used file and pos data
Operate from the service container
mysql Command line input
change master to master_host='172.17.0.2', master_user='slave', master_password='123456', master_port=3306, master_log_file='mysql-bin.000001', master_log_pos= 154, master_connect_retry=60;
master_log_pos=154 , Is the maximum position of the value record
master_host :Master The address of , It refers to the independence of the container ip
master_port:Master Port number , Refers to the port number of the container
master_user: Users for data synchronization
master_password: Password of the user for synchronization
master_log_file: Appoint Slave From which log file to start copying data , As mentioned above File Value of field
master_log_pos: From which Position Start reading , As mentioned above Position Value of field
master_connect_retry: If the connection fails , Retry interval , The unit is seconds , The default is 60 second
start slave;
Enable master-slave backup
show slave status \G
Check the status
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
The last two values are yes Open successfully , If there is no perhaps connection It means opening failed .
版权声明
本文为[Oaa114 dragon boy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231125175871.html
边栏推荐
- Applet payment
- MIT: label every pixel in the world with unsupervised! Humans: no more 800 hours for an hour of video
- After the MySQL router is reinstalled, it reconnects to the cluster for boot - a problem that has been configured in this host before
- PCB的注意事项
- Laravel绑定钉钉群警报(php)
- MQ的了解
- Study notes of C [8] SQL [1]
- ImportError: libX11.so.6: cannot open shared object file: No such file or directory
- mysql创建存储过程及函数详解
- Interpreting the art created by robots
猜你喜欢

MIT: label every pixel in the world with unsupervised! Humans: no more 800 hours for an hour of video

Canvas详解

MQ的了解

Overall plan management mode in maker Education

qt 64位静态版本显示gif

Usage of rename in cygwin

Interpreting the art created by robots

Summary of the relationship among GPU, CUDA and cudnn

redis优化系列(二)Redis主从原理、主从常用配置

云呐|固定资产盘点中,支持多种盘点方式(资产清查盘点)
随机推荐
让中小学生在快乐中学习的创客教育
Explain in detail the pitfalls encountered in DTS due to the time zone problems of timestamp and datetime in MySQL
年度最尴尬的社死瞬间,是Siri给的
少儿编程结构的改变之路
采用百度飞桨EasyDL完成指定目标识别
怎么进行固定资产盘点,资产盘点报告如何一键生成
项目实训-火爆辣椒
微型机器人的认知和研发技术
Nacos Foundation (8): login management
qt 64位静态版本显示gif
MySQL Router重装后重新连接集群进行引导出现的——此主机中之前已配置过的问题
Usage Summary of datetime and timestamp in MySQL
Learn go language 0x07: stringer exercise code in go language journey
零钱兑换II——【LeetCode】
docker MySQL主从备份
Cognition and R & D technology of micro robot
ImportError: libX11.so.6: cannot open shared object file: No such file or directory
汇编语言 运行环境设置等教程链接整理
Laravel adds custom helper functions
mysql创建存储过程及函数详解