博客
关于我
mysql8主从复制
阅读量:686 次
发布时间:2019-03-17

本文共 1277 字,大约阅读时间需要 4 分钟。

技术文档:主从复制服务器配置指南

主服务器配置

1. 登陆主服务器

连接到主服务器IP地址信息(192.168.2.84):

[root@youyun-284 mysql]# mysql -uroot -p

2. 创建复制服务用户

使用数据库权限管理命令创建‘repl’用户:

CREATE USER 'repl'@'%' IDENTIFIED BY '*********';flush privileges;

3. 配置my.cnf文件

定zenith定期修改my.cnf文件,确保以下设置:

server-id = 1binlog_format = mixedlog-bin = master-a-binexpire_logs_days = 7max_binlog_size = 100mbinlog_cache_size = 4mmax_binlog_cache_size = 512mbinary_do_db = pay-order#binlog_do_db = pay-channel

4. 授权从服务器账号

在主服务器上授予从服务器复制权限:

GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';flush privileges;

5. 重启MySQL服务

# 使用 systemctl 命令(CentOS/RedHat]systemctl restart mysql# 或者使用 systemctl# systemctl stop mysql && systemctl start mysql

从服务器配置

6. 记录主服务器信息

在从服务器上设置主服务器详细信息:

change master to  master_host='IP地址信息',  master_port=3306,  master_user='repl',  master_password='*********',  master_log_file='master-bin.000001',  master_log_pos=10000;

7. 启动从服务器

mysql> start slave;

8. 查看从服务器状态

验证从服务状态:

show slave status \G;

重点关注以下状态 ```Slave_IO_State: Waiting for master to send eventSlave_IO_Running: YesSlave_SQL_Running: Yes

### 9. 解锁主表```bashmysql> unlock table;

通用注意事项

  • 数据同步锁表:在启动复制前,对目标数据库表进行锁定,确保只读模式直到备用服务器就绪。
  • 错误排查:如同步异常,检查各错误信息(Last_Error,Last_SQL_Error)以确定具体问题。
  • 日志管理:合理设置expire_logs_days和max_binlog_size,防止磁盘使用过多。

如需进一步帮助,可参考具体数据库文档或技术支持。

转载地址:http://hlxhz.baihongyu.com/

你可能感兴趣的文章
Python3连接MySQL
查看>>
Python关于isinstance函数的解析 | 附Demo(全)
查看>>
Python3:setup.py:完成所有任务的PIP安装(Build_ext+Install)
查看>>
python4.0 gil_Python 并发编程系列--1、浅谈GIL历史及对多线程的影响
查看>>
python60行绘图程序_天底下最简单的QT画图板,就一个类,60行代码
查看>>
Python: AES加密与解密
查看>>
Python: Range() 最大尺寸;动态的还是静态的?
查看>>
Python: Windows下用 multiprocessing 的深坑
查看>>
python:Could not find platform independent libraries <prefix>解决方法
查看>>
Python:datetime tzinfo 时区名称文档
查看>>
Python:deepcopy(list) vs new_list = old_list[:]
查看>>
Python:Google API - 从消息中获取 mimeTypes
查看>>
Python:Google API - 从消息中获取 mimeTypes
查看>>
Python:subprocess.call,stdout to file,stderr to file,在屏幕上实时显示stderr
查看>>
Python:TypeError:无法连接“str“和“int“对象
查看>>
Python:XPath 在 ElementTree 中不可用
查看>>
Python:从 FTP 服务器下载文件
查看>>
python:从列表中创建元组列表
查看>>
Python:从嵌套列表中删除重复项
查看>>
Python:从间隔映射到值
查看>>