mysql 主从搭建

两台mysql服务
server1:172.26.92.86 (主数据库)
server2:172.26.92.87 (从数据库)

修改配置文件 /etc/my.cnf

#主服务器配置
#开启二进制日志
log-bin=master-bin
#使用二进制日志的索引文件
log-bin-index=master.bin.index
#为服务器添加唯一编号
server-id=1
启动mysql服务
create user ‘jk’@’%’ identified by ‘password’
grant all privileges on . to jk identified by ‘password’;

从服务器配置 /etc/my.cnf
server-id=2
relay-log=slave-relay-log-bin
relay-log-index=slave-relay-log-bin.index
启动从服务器,并进入
mysql>change master to master_host=‘172.26.92.86’,master_port=3306,master_user=‘jk’,master_password=‘password’;
mysql>start slave;

查看节点状态#show slave status\G;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
主要看这两个参数是否为Yes

配置主从可参考https://blog.csdn.net/a281246240/article/details/83343166 过于复杂,可借鉴
常见问题处理参考:http://blog.chinaunix.net/uid-20809130-id-5758642.html

出现异常时可按下面步骤处理
Relay_Master_Log_File: mysql-bin.000010
Exec_Master_Log_Pos: 821
mysql> stop slave;
Query OK, 0 rows affected (0.01 sec)
mysql> CHANGE MASTER TO MASTER_LOG_FILE=‘mysql-bin.000010’,MASTER_LOG_POS=821;
Query OK, 0 rows affected (0.01 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G;

你可能感兴趣的:(mysql,主从)