当前位置:网站首页>MySQL主从搭建(问题大聚集,告别部署烦恼)
MySQL主从搭建(问题大聚集,告别部署烦恼)
2022-08-02 18:11:00 【Slcp】
MySQL主从搭建
前言
公司规定,生产环境中一旦与数据(缓存也不例外)扯上关系的一律不由k8s统一管理
因此,别想一键式部署了,只能老老实实单独部署
再此,就记录一下搭建过程,分享给小伙伴们,避免浪费时间
废话不多说,上车
下载
没有安装mysql,我这边也给大伙们准备了~
配置
1、master和node二台服务器,分别到/etc/my.cnf配置文件, 在mysqld里添加一下属性
#master
[mysqld]
server-id=101
log-bin = mysql-bin
auto-increment-increment = 2
auto-increment-offset = 1000
#node
[mysqld]
server-id=103
log-bin = mysql-bin
auto-increment-increment = 2
auto-increment-offset = 1001
2、进入Mysql,分别为二台master创建各种的用户供对方使用
温馨提示: 本案例为双主从,也就是master同步到node,node同步到master。单主从,就只需要不执行带*即可
#master的机器上
CREATE USER 'master'@'%' IDENTIFIED BY '123456';
#node的机器上(*)
CREATE USER 'node'@'%' IDENTIFIED BY '123456';
3、分别给用户授予复制权限
#master的机器上
GRANT REPLICATION SLAVE ON *.* TO 'master'@'%' identified by '123456';
#刷新
flush privileges;
#node的机器上(*)
GRANT REPLICATION SLAVE ON *.* TO 'node'@'%' identified by '123456';
#刷新
flush privileges;
4、分别重启服务,登录mysql用户,通过show master status 查看二进制文件名称还有pos位置,为slave配置复制位置
master

node

5、分别切换master,注意master_log_file还有master_log_pos mysql里面操作
#node的机器上
change master to master_host='master服务器ip',master_user='master',master_password='123456',master_log_file='mysql-bin.000001',master_log_pos=154;
#master的机器上(*)
change master to master_host='node服务器ip',master_user='node',master_password='123456',master_log_file='mysql-bin.000002',master_log_pos=154;
6、分别利用命令启动slave
#启动
start slave;
#关闭
stop slave;
7、测试结果,在master上创建数据库,node是否能同步,然后再在node上创建表写数据,看master能否同步。

安装完成之后,所有mysql重启就可以了
其他问题
- ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
很显然,系统提示我们需要更改密码。一般出现这种情况是第一次登录时,需要先修改密码后才能操作。
set password for root@localhost=password('123456');
- Slave_SQL_Running:no:

解决办法如下:
stop slave;
SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
START SLAVE;
show slave status;
- Slave_IO_Running: No
#解决办法
stop slave;
#根据master重新设置file和pos
CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000026',MASTER_LOG_POS=0;
slave start;
show slave status;
- 数据库主从日志很大
设置只保留30天的binlog
(临时,重启mysql这个参数会失败)
set global expire_logs_days = 30;
(永久,my.cnf中添加,重启后生效)、
expire_logs_days = 30
查看当前的日志保存天数
show variables like ‘expire_logs_days’;
- 若有其他未提及问题,进行留言,小编会及时回复~
边栏推荐
猜你喜欢

Technical life | How to draw a big picture of business

redis总结_分布式缓存

LeetCode 2336. 无限集中的最小数字(SortedSet)

Smart Microelectronics Releases Low-Power MM32L0130 Series MCU Products

基于HDF的LED驱动程序开发(1)

From the technical panorama to the actual scene, analyze the evolutionary breakthrough of "narrowband high-definition"

Monitor is easy to Mars debut: distributed operations help TOP3000 across management gap

在线文档Sheet技术解析

Win11主题下载一直转圈怎么办?Win11主题下载一直转圈的解决方法
![Open Source Summer | [Cloud Native] DevOps (5): Integrating Harbor](/img/db/16ae82217382e72824a4b454060833.png)
Open Source Summer | [Cloud Native] DevOps (5): Integrating Harbor
随机推荐
NeRF: The Secret of 3D Reconstruction Technology in the Popular Scientific Research Circle
CUDA+Pycharm-gpu版本+Anaconda安装
从技术全景到场景实战,透析「窄带高清」的演进突破
POE交换机常见问题解答
面试官:可以谈谈乐观锁和悲观锁吗
AtomicInteger详解
golang刷leetcode 字符串(4)逆波兰式
浅谈混迹力扣和codeforces上的几个月
Data Governance: The Evolution of Data Integration and Application Patterns
千万级QPS下服务如何才能平滑启动
开源一夏 | Web开发(七):登录实现及功能测试
注释
Redis总结_实战篇
载20(S)-人参皂苷/细胞穿膜肽-单克隆抗体-载丝裂霉素白蛋白纳米微球的制备
leetcode:622. 设计循环队列【循环队列板子】
How can services start smoothly under tens of millions of QPS
Win11主题下载一直转圈怎么办?Win11主题下载一直转圈的解决方法
redis总结_基础
My recursive never burst stack
Smart Microelectronics Releases Low-Power MM32L0130 Series MCU Products