MySQL主从复制配置

625 查看

服务器地址

主服务器:192.168.0.21
从服务器:192.168.0.22

主服务器配置

修改my.cnf中如下配置:

server_id = 1

log_bin=mysql-bin

expire-logs-days=30
binlog-do-db=yliyun
binlog-do-db=yliyun_log
binlog-ignore-db=test

登入mysql
创建复制用户并授权:

grant replication slave on *.* to 'rep'@'192.168.0.22' identified by 'yliyun123';

查看日志状态:

show master status;

+------------------+----------+-------------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB      | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+-------------------+------------------+-------------------+
| mysql-bin.000026 |   539641 | yliyun,yliyun_log | test             |                   |
+------------------+----------+-------------------+------------------+-------------------+

从服务器配置

修改my.cnf中如下配置:

server_id = 2

登入mysql
设置主服务器及日志信息:

change master to master_host='192.168.0.21', master_user='rep', master_password='yliyun123', master_log_file='mysql-bin.000026', master_log_pos=539641;

开始复制:

start slave;

查看复制状态:

show slave status\G;