环境:
master: 192.168.1.240slave: 192.168.1.201
master端:
yum install mysql mysql-server mysql-develvim /etc/my.cnfserver-id = 1log-bin=mysql-binbinlog_format = mixedbinlog-ignore-db = mysqlbinlog-ignore-db = testbinlog-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.000001Position: 239
slave端:
yum install mysql mysql-server mysql-devel vim /etc/my.cnfserver-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: YesSlave_SQL_Running: Yes
至此,在master(主库)端进行增删改等操作会同步到slave(从库)