- installation of 2 Mysql:ip Address 192.168.1.1 (Master master database), respectively, 192.168.1.2 (slave from Database), Ps:mysql version 5.5 or higher.
- Modify Master master database my.cnf file ( need to restart MySQL to complete the modification)
[Mysqld]server-id = 1 binlog-do-db=test #要同步的数据库, if you have more than one database, repeat this parameter for each database row Log-bin=mysql-bin #要生成的二进制日记文件名称
Master Main Library Add User=slave is responsible for synchronizing the main library data ( Note: The initial data of the master-slave database should be consistent )
#建立一个帐户slave, and can only be accessed from 192.168.1.2 this address (slave), the password is 123456. Create user ' slave ' @ ' 192.168.1.2 ' identified by ' 123456 '; #为slave用户设置REPLICATION slave permissions Grant REPLICATION slave on * * to ' Slave ' @ ' 192.168.1.2 ';
-
Master Main Library sql: mysql> Show Master Status ;
Remember the value of the File,position field
- Modify slave from library my.cnf (modify to complete restart MySQL)
change Master to master_host= ' 192.168.1.1 ', master_port=3306,master_user= ' slave ', master_password= ' 123456 ', master_ Log_file= ' mysql-bin.000002 ', master_log_pos=1302;
master_log_file, master_log_pos corresponds to the value of the file,position in the 4th step.
Open slave:mysql> slave start;
Available by: mysql> show slave status;   View slave status
done.
Simple MySQL master-slave configuration