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: