Mysql 主从复制  

主 IP : 1.2.3.7

从 IP : 1.2.3.4




Mysql主服务器


vi my.cnf


[mysqld]

log-bin = mysql-bin //必须开启二进制日志

server-id = 1 //确保这个id号没有被其他服务器使用



create user sync@'localhost' identified by '123456';


flush privileges;


grant replication slave on *.* to sync@'1.2.3.4' identified by '123456';


mysql> show master status;

+------------------+----------+--------------+------------------+-------------------+

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

+------------------+----------+--------------+------------------+-------------------+

| mysql-bin.000020 |      676 |              |                  |                   |

+------------------+----------+--------------+------------------+-------------------+

1 row in set (0.00 sec)



Mysql 从服务器


vi my.cnf


[mysqld]

log-bin = mysql-bin //必须开启二进制日志

server-id = 2 //确保这个id号没有被其他服务器使用



连接数据库


mysql> change master to


mysql> master_host='1.2.3.7',master_user='sync',master_password='123456',master_log_file='mysql-bin.000020',master_log_pos=676;


mysql> start slave;


mysql> show slave status\G;


你可能感兴趣的:(mysql,ab)