博客
关于我
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/

你可能感兴趣的文章
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>