master 配置
修改/etc/my.cnf配置文件加入
log-bin=mysql-bin
binlog_format=mixed
server-id=101//注意id不能重复
添加同步账号 mysync 密码 Q!W@E#R$,用于复制操作的用户
create user 'mysync'@'%' IDENTIFIED WITH mysql_native_password BY 'Q!W@E#R$';
GRANT REPLICATION SLAVE ON *.* TO 'mysync'@'%';
//REPLICATION SLAVE 分配复制权限 ,*.* 可操作哪个数据库
flush privileges;
show MASTER STATUS;
+------------------+----------+--------------+------------------+-------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------------+
| mysql-bin.000001 | 815 | | | |
+------------------+----------+--------------+------------------+-------------------------+
1 row in set (0.00 sec)
slave 配置
修改/etc/my.cnf配置文件加入
log-bin=mysql-bin
binlog_format=mixed
server-id=102 //注意id不能重复
CHANGE MASTER TO master_host='47.98.253.246', master_user='mysync',master_password='Q!W@E#R$', master_log_file='mysql-bin.000001',master_log_pos=815;
master_host 主机ip
master_user 主机用户
master_password 主机密码
master_log_file 同步文件,文件为上一步show MASTER STATUS;结果中的mysql-bin.000001
master_log_pos 起始位置文件为上一步show MASTER STATUS;结果中的815
查看主从状态
show slave status\G;
开启主从同步
start slave;
在查看主从状态
show slave status\G;