mysql主从复制基于binlog+position搭建


1.环境
----------------------------------------------------------|
|mysql版本  | 5.7.14                |  5.7.14              |
|----------|----------------------------------------------|
|ip        |192.168.26.233(master) | 192.168.26.75 (slave)|
|port      | 3306                  |       3306           |
|---------------------------------------------------------|

master端操作

1. 主库必备参数:

server-id=3306100
log-bin = /data/mysql/mysql_3306/logs/mysql-bin
binlog_format=row

可选: row

2. 获取position和binlog位置


mysql> show master status\G;
*************************** 1. row ***************************
             File: mysql-bin.000016
         Position: 154
     Binlog_Do_DB: 
 Binlog_Ignore_DB: 
Executed_Gtid_Set: 
1 row in set (0.00 sec)



3.创建复制账号

mysql> create user 'repl'@'192.168.26.%' identified by 'repl';
Query OK, 0 rows affected (0.01 sec)

mysql> grant replication slave on *.* to 'repl'@'192.168.26.%';
Query OK, 0 rows affected (0.00 sec)


mysql> select user,host from mysql.user;
+-----------+--------------+
| user      | host         |
+-----------+--------------+
| repl      | 192.168.26.% |
| admin     | localhost    |
| mysql.sys | localhost    |
| root      | localhost    |
+-----------+--------------+
4 rows in set (0.00 sec)



4.在slave机器上测试账号能不能登陆

[root@zw_test_26_75 ~]# mysql -h 192.168.26.233 -urepl -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.14-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
[email protected] [(none)]>

slave端操作

1. 从库必备参数:

server-id=3306101   (server-id不能重复) 
log-bin = /data/mysql/mysql_3306/logs/mysql-bin
log_slave_updates 

如果没加log_slave_updates 参数复制的时候  a->b->c不行的

2. 生成一个 change master to 语句,执行

[email protected] [(none)]>help change master to

root@localhost [(none)]>change master to master_host='192.168.26.233', master_port=3306, master_user='repl',master_password='repl',master_log_file='mysql-bin.000016',master_log_pos=154;
Query OK, 0 rows affected, 2 warnings (0.77 sec)


3.查看slve的状态

mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: 
                  Master_Host: 192.168.26.233
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000016
          Read_Master_Log_Pos: 154
               Relay_Log_File: relay-bin.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File: mysql-bin.000016
             Slave_IO_Running: No  --正常应该是yes
            Slave_SQL_Running: No  --正常应该是yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值