The steps are as follows:1. Modify Master server Master:#vi/etc/my.cnf[Mysqld]Log-bin=MySQL-bin//[must] enable binary loggingserver-id=222//[must] server unique ID, default is 1, usually take IP last paragraph2. Modify the slave from the server:#vi/etc/my.cnf[Mysqld]Log-bin=MySQL-bin//[not required] enable binary logserver-id=226//[must] server unique ID, default is 1, usually take IP last paragraph3, restart MySQL for both servers/etc/init.d/MySQLRestart4. Establish an account on the primary server and authorize slave:#/usr/local/mysql/bin/mysql-uroot-pmttang MySQL>grant REPLICATION SLAVE on. To ' mysync ' @ '% ' of ' identified by ' q123456 ';//generally do not use the root account,“%” means that all clients may even, as long as the account, the password is correct, here can be specific client IP instead, such as 192.168.145.226, enhance security. 5, log on to the master server MySQL, query the status of MasterMySQL>Show master status; +------------------+----------+--------------+------------------+ |File| Position | binlog_do_db | binlog_ignore_db | +------------------+----------+--------------+------------------+ |MySQL-bin.000004 | 308 | | | +------------------+----------+--------------+------------------+ 1 row in Set (0.00sec) Note: Do not operate the master server MySQL again after performing this step to prevent the change of the primary server state value6, configure the slave from the server:MySQL>change Master to master_host= ' 192.168.145.222 ', master_user= ' Mysync ', master_password= ' q123456 ',Master_log_file= ' mysql-bin.000004 ', master_log_pos=308;//Be careful not to disconnect, there are no single quotes around 308 digits. Mysql>start slave;//To start the Copy from Server feature7, check the status of the replication function from the server:MySQL>Show Slave Status\g1. Row ***************************slave_io_state: Waiting forMaster to send event Master_host: 192.168.2.222//Primary server addressMaster_user:mysync//authorization account name, try to avoid using rootmaster_port:3306//database port, some versions do not have this lineConnect_retry:60Master_log_file:MySQL-bin.000004Read_master_log_pos: 600//#同步读取二进制日志的位置, greater than or equal to Exec_master_log_posrelay_log_file:ddte-relay-bin.000003Relay_log_pos: 251Relay_master_log_file:MySQL-bin.000004slave_io_running: Yes//This state must be YesSlave_sql_running:yes//This state must be Yes......
Implementing Master-slave replication of the database (MySQL)