mysql5.7在centos6.5下主从配置

环境:

主(Master) windows:10.20.29.45

从(Slave) centos7:10.20.29.46

配置主服务器 


修改my.com文件。在[mysqld]段下添加: 

#要给从机同步的库
binlog-do-db=test
#不给从机同步的库
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
binlog-ignore-db=sys
#自动清理 7 天前的log文件,可根据需要修改
expire_logs_days=7
# 启用二进制日志
log-bin=mysql-bin
# 服务器唯一ID,一般取IP最后一段
server-id=45

测试log_bin是否成功开启: 
mysql> show variables like '%log_bin%';  

重启mysql服务器:

建立账户并授权slave 

mysql> GRANT FILE ON *.* TO 'backup'@'%' IDENTIFIED BY '123456';
Query OK, 0 rows affected, 1 warning (0.05 sec)

mysql> GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* to 'backup'@'%' identified by '123456'; 
Query OK, 0 rows affected, 1 warning (0.04 sec)

 

查询主服务器的状态: 
 

mysql> show master status; 
+------------------+----------+--------------+-------------------------------------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB                                | Executed_Gtid_Set |
+------------------+----------+--------------+-------------------------------------------------+-------------------+
| mysql-bin.000003 |      715 | test-cluster | mysql,information_schema,performance_schema,sys |                   |
+------------------+----------+--------------+-------------------------------------------------+-------------------+
1 row in set (0.00 sec)

 

配置从服务器 


修改my.com文件。在[mysqld]段下添加:

server-id=46
#加上以下参数可以避免更新不及时,SLAVE 重启后导致的主从复制出错。
read_only = 1
master_info_repository=TABLE
relay_log_info_repository=TABLE

重启服务器 :

关闭 slave

mysql> stop slave;   
Query OK, 0 rows affected (0.07 sec)
change master to master_host='10.20.29.45',master_port=3306,master_user='backup',master_password='123456',master_log_file='mysql-bin.000003',master_log_pos=715;

master_port为mysql服务器端口号(无引号),master_user为执行同步操作的数据库账户,715就是show master status 中看到的position的值,这里的mysql-bin.000003就是file对应的值

启动 slave

mysql> start slave;
Query OK, 0 rows affected (0.04 sec)

查看从服务器状态 :show slave status \G

 

Slave_IO_Running: Yes //此状态必须YES

Slave_SQL_Running: Yes //此状态必须YES

 

测试

在主服务器的test库新建一张表,并插入数据,看从服务器是否自动复制即可。如果配置正确,应该可以的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值