当前位置:网站首页>docker MySQL主从备份
docker MySQL主从备份
2022-04-23 11:25:00 【oaa114龙仔】
1.下载mysql:5.7镜像
docker pull mysql:5.7
2.创建挂载目录
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.创建主服务器
创建主容器
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
进入主容器并将my.cnf删除
docker exec -it sqlms bin/bash
rm -rf my.cnf
exit
退出容器
主机内配置主服务器
进入挂载目录
cd /root/sqlms/conf.d
创建一个mysql配置文件
vi my.cnf
#开启bin-log日志并给与一个id
[mysqld]
server-id=1
log-bin=mysql-bin
然后进主容器内将my.cnf移动到原来的目录
mv my.cnf /etc/mysql/
docker restart sqlms
创建从服务容器
创建从服务器
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
重复主服务容器的操作直到mysql配置文件
修改从mysql配置文件
进入挂载目录
cd /root/sqlms/conf.d
生成配置文件
vi my.cnf
[mysqld]
server-id=2
log-bin=mysql-slave-bin
relay_log=edu-mysql-relay-bin
重启服务
docker restart sqlsl
准备环节结束开始正式操作
主服务容器操作
进入主容器启动mysql
docker exec -it sqlms bin/bash
mysql -uroot -proot
在命令行输入
CREATE USER 'slave'@'%' IDENTIFIED BY '123456';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'slave'@'%';
创建一个slave用户并授权读写任何文件权限,用于主从备份数据
show master status;

需要使用到file和pos数据
从服务容器操作
mysql命令行输入
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 ,就是值记录最大位置
master_host :Master的地址,指的是容器的独立ip
master_port:Master的端口号,指的是容器的端口号
master_user:用于数据同步的用户
master_password:用于同步的用户的密码
master_log_file:指定 Slave 从哪个日志文件开始复制数据,即上文中提到的 File 字段的值
master_log_pos:从哪个 Position 开始读,即上文中提到的 Position 字段的值
master_connect_retry:如果连接失败,重试的时间间隔,单位是秒,默认是60秒
start slave;
开启主从备份
show slave status \G
查看状态
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
上两项值都是yes则开启成功,如果其中有no或者connection就代表开启失败。
版权声明
本文为[oaa114龙仔]所创,转载请带上原文链接,感谢
https://blog.csdn.net/vxandox/article/details/124351294
边栏推荐
- Learning go language 0x01: start from the official website
- qt5.8 64 位静态库中想使用sqlite但静态库没有编译支持库的方法
- 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
- Mysql排序的特性详情
- MIT:用无监督为世界上每个像素都打上标签!人类:再也不用为1小时视频花800个小时了
- 项目实训-火爆辣椒
- 初探 Lambda Powertools TypeScript
- Advanced file IO of system programming (13) -- IO multiplexing - Select
- 解读机器人编程课程的生物认知度
- Study notes of C [8] SQL [1]
猜你喜欢

论坛系统数据库设计

赛微微电科创板上市破发:跌幅达26% 公司市值44亿

Interprocess communication -- message queue

Laravel绑定钉钉群警报(php)

VM set up static virtual machine

nacos基础(9):nacos配置管理之从单体架构到微服务

Summary of the relationship among GPU, CUDA and cudnn

配电房远程综合监控系统在10kV预制舱项目中的应用

Upgrade the functions available for cpolar intranet penetration

PDMS soft lithography process
随机推荐
After the MySQL router is reinstalled, it reconnects to the cluster for boot - a problem that has been configured in this host before
进程间通信 -- 消息队列
Get things technology network optimization - CDN resource request Optimization Practice
RebbitMQ的初步了解
PDMS soft lithography process
Solve the problem of "suncertpathbuilderexception: unable to find valid certification path to requested target"
零钱兑换II——【LeetCode】
Summary of the relationship among GPU, CUDA and cudnn
Advanced file IO of system programming (13) -- IO multiplexing - Select
Learning go language 0x02: understanding slice
解决由于找不到amd_ags_x64.dll,无法继续执行代码。重新安装程序可能会解决此问题,地平线(Forza Horizon 5)
活动进行时! 点击链接加入直播间参与“AI真的能节能吗?”的讨论吧!
R-drop: a more powerful dropout regularization method
Study notes of C [8] SQL [1]
MIT: label every pixel in the world with unsupervised! Humans: no more 800 hours for an hour of video
Implementation of partition table of existing data table by MySQL
Redis optimization series (II) redis master-slave principle and master-slave common configuration
Detailed introduction to paging exploration of MySQL index optimization
创客教育中的统筹方案管理模式
Learn go language 0x06: Fibonacci closure exercise code in go language journey