Mysql-主从复制配置

Mysql-主从复制配置

master开启binlog

1
2
3
4
5
6
7
8
vi /etc/my.cnf

log-bin=mysql-bin
binlog_format=mixed
server-id=1
auto_increment_increment=2
auto_increment_offset=1
replicate-do-db=monitor

master重启

1
systemctl restart mysqld

master设置复制用户

1
2
3
4
5
6
7
8
9
10
mysql>GRANT REPLICATION SLAVE ON *.* TO 'repuser'@'192.168.8.%' IDENTIFIED BY '2014Picc!!!';
mysql>FLUSH PRIVILEGES;
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 | 1977 | | | |
+------------------+----------+--------------+------------------+-------------------+

--记录file和position

slave设置参数

1
2
3
vi /etc/my.cnf

server-id=2

slave重启

1
systemctl restart mysqld

slave开启复制

1
mysql>change master to master_host='192.168.8.201', master_user='repuser', master_password='2014Picc!!!', master_log_file='mysql-bin.000001', master_log_pos=612;

slave查看状态

1
mysql>show slave status\G