MySQL主从
-
先分别部署两个mysql服务.
-
在其中一个主上面分配权限
grant replication slave on *.* to `rep1`@`%`IDENTIFIED BY 123
-
修改主上面的配置文件,并重启,之后可以
show master status;
log-bin=/var/lib/mysql/binlog server-id=1 binlog-do-db=指定要复制的库名
-
配置从机
server-id=2
- 从机执行命令
change master to master_host=主服务器IP, master_port=3306,master_user='rep1',
master_password='123',
master_log_file='binlog.000001',
master_log_pos=154
- 从机 start slave; 然后 show slave status查看 Slave_IO_Running Slave_SQL_Running 这两个状态都为YES就行了。