大佬教程收集整理的这篇文章主要介绍了MySQL主从复制,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
系统版本:centos 7
1、服务器:
server1:182.92.209.212 master
server1:182.92.97.73 salve
2、myslq版本:
@H_37_21@mysql -V 命令查看MySQL数据库的版本,两台服务器版本一致,不知版本不一致是否有问题。
3、连接
查看是否能ping通另外一台服务器
4、关闭防火墙
1:查看防火状态 systemctl status firewalld service iptables status 2:暂时关闭防火墙 systemctl stop firewalld service iptables stop 3:永久关闭防火墙 systemctl disable firewalld chkconfig iptables off 4:重启防火墙 systemctl enable firewalld service iptables restart
#vi /etc/my.cnf
[mysqld] log-bin=mysql-bin //[必须]启用二进制日志 server-id=222 //[必须]服务器唯一ID,默认是1,一般取IP最后一段
#vi /etc/my.cnf
[mysqld] log-bin=mysql-bin //[不是必须]启用二进制日志 server-id=226 //[必须]服务器唯一ID,默认是1,一般取IP最后一段
/etc/init.d/mysqld restart
百分号表示所有客户端都可能连
注意:到这一步先不要动主机MYSQL,防止主服务器状态值变化
如果这一步出错了,去到最后先取消主从复制,再接着继续操作!
//启动从服务器复制功能:
mysql> show slave statusG
*************************** 1. row *************************** Slave_IO_State: WaiTing for master to send event Master_Host: 182.92.209.212 Master_User: zhixi Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000015 Read_Master_Log_Pos: 154 Relay_Log_File: zhizuo-relay-bin.000002 Relay_Log_Pos: 320 Relay_Master_Log_File: mysql-bin.000015 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 154 Relay_Log_Space: 528 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 202 Master_UUID: eb116683-ed0d-11eb-8a01-00163e361c72 Master_Info_File: /www/server/data/master.info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiTing for more @R_262_9531@es Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_timestamp: Last_SQL_Error_timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 Replicate_Rewrite_DB: ChAnnel_Name: Master_TLS_Version: 1 row in set (0.00 seC)
注:Slave_IO及Slave_SQL进程必须正常运行,即YES状态,否则都是错误的状态(如:其中一个NO均属错误)。
以上主从复制搭建完成!
主服务器Mysql,建立数据库,并在这个库中建表插入一条数据:
从机查看主机插入的数据是否过来:
成功!
以上是大佬教程为你收集整理的MySQL主从复制全部内容,希望文章能够帮你解决MySQL主从复制所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。