环境:
master: 192.168.1.240 slave: 192.168.1.201
master端:
yum install mysql mysql-server mysql-devel vim /etc/my.cnf server-id = 1 log-bin=mysql-bin binlog_format = mixed binlog-ignore-db = mysql binlog-ignore-db = test binlog-ignore-db = information_schema service mysqld start mysql> grant replication slave on *.* to'repl'@'%' identified by '123456'; mysql> show master status\G;
记录当前二进制日志文件以及位置
File: mysql-bin.000001 Position: 239
slave端:
yum install mysql mysql-server mysql-devel vim /etc/my.cnf server-id = 2 service mysqld start mysql>change master tomaster_host='192.168.1.240', \ master_user='repl', \ master_password='123456', \ mater_port='3306', \ master_log_file='mysql-bin.000001', \ master_log_pos=239; mysql> start slave; mysql> show slave status\G; Slave_IO_Running: Yes Slave_SQL_Running: Yes
至此,在master(主库)端进行增删改等操作会同步到slave(从库)