首页 > 代码库 > mysql主从同步

mysql主从同步

1.修改配置文件

主服务器master:

[mysqld]
log-bin=mysql-bin

server-id=222

 

修改从服务器slave:

[mysqld]
log-bin=mysql-bin 
server-id=226

重启两台服务器的mysql

 

2.在主服务器上建立帐户并授权slave:

GRANT REPLICATION SLAVE ON *.* to ‘son‘@‘%‘ identified by ‘a123456‘;

show master status;

记住, File,Position

 

3.配置从服务器Slave:

change master to master_host=‘192.168.0.113‘,master_user=‘son‘,master_password=‘a123456‘,master_log_file=‘mysql-bin.,000009‘,master_log_pos=240;

 

4.查看结果开启同步

Mysql>start slave;

mysql> show slave status\G