当前位置:网站首页>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
边栏推荐
- Share two practical shell scripts
- Learn go language 0x05: the exercise code of map in go language journey
- AcWing 1874. 哞加密(枚举,哈希)
- Detailed explanation of integer data type tinyint in MySQL
- Redis optimization series (II) redis master-slave principle and master-slave common configuration
- GPU, CUDA,cuDNN三者的關系總結
- Interprocess communication -- message queue
- PyTorch 神经网络训练器
- Significance of actively participating in middle school robot competition
- Résumé de la relation entre GPU, cuda et cudnn
猜你喜欢
qt5.8 64 位静态库中想使用sqlite但静态库没有编译支持库的方法
创客教育中的统筹方案管理模式
QT 64 bit static version display gif
系统编程之高级文件IO(十三)——IO多路复用-select
qt5. 8. You want to use SQLite in the 64 bit static library, but the static library has no method to compile the supporting library
On lambda powertools typescript
分享两个实用的shell脚本
初探 Lambda Powertools TypeScript
RebbitMQ的初步了解
Advanced file IO of system programming (13) -- IO multiplexing - Select
随机推荐
golang之笔试题&面试题01
Summary of QT semaphore unresolved errors
少儿编程结构的改变之路
解析幼儿教育中steam教育的融合
MySQL sorting feature details
ImportError: libX11.so.6: cannot open shared object file: No such file or directory
年度最尴尬的社死瞬间,是Siri给的
VM set up static virtual machine
解读机器人创造出来的艺术
nacos基础(5):nacos配置入门
卷积层和池化层总结
ES6学习笔记二
Interpreting the art created by robots
Applet payment
qt5. 8. You want to use SQLite in the 64 bit static library, but the static library has no method to compile the supporting library
MQ在laravel中简单使用
采用百度飞桨EasyDL完成指定目标识别
Pytorch neural network trainer
[Web 每日一练] 八色拼图(float)
Link sorting of tutorials such as assembly language running environment setting