Implementation process:
(1) Master changes the record to binary log (these are called binary log events, binary logs event);
(2) Slave copies the binary log events of master to its trunk logs (relay log);
(3) Slave redo the event in the trunk log and change the data to reflect its own.
Related commands:
mysql> start slave; #启动slave
mysql> stop Slave; #停止
Mysql> show slave status \g; #查看slave状态
mysql> Reset Slave; #重置slave配置
Mysql> Show master status; #查看bin-log Status
Configuration implementation:
master configuration (in my.cnf ):
server-id=129
Log-bin=mysql-bin
Binlog-format=mixed
Slave configuration (in my.cnf):
server-id=130
Relay-log=mysql-relay
Create an account on Master and authorize:
mysql> Grant Replication client,replication slave on * * to ' repl ' @ ' 172.%.%.% ' identified by ' repl ';
mysql> FLUSH privileges;
Set on Slave:
Mysql> Change Master to
Master_host= ' 172.16.24.129 ',
Master_user= ' Tianbao ',
Master_password= ' Tianbao ',
Master_log_file= ' mysql-bin.000002 ',
master_log_pos=1099;
mysql> start slave;
Problems encountered:
#查看servid和配置文件中是否一致
ERROR HY000: The server is not configured as slave; Fix in config file or with change MASTER to
#重置slave (reset Slave), and from the new configuration, and then start slave
ERROR 1201 (HY000): Could not initialize master info structure; More error messages can is found in the MySQL error log
#状态不对. Check the Authorized account information, check the starting location of the log file Master_log_pos is consistent with the master. Show Master Status View bin-log information
Slave_io_state:connecting to master.
mysql-Master-slave replication