Configuring bitsCN.com on the MySQL master/slave server
MySQL master/slave server configuration
The configuration of the master server (master) is very simple. you only need to modify the two points in the my. cnf configuration file.
Modify the server_id attribute in my. cnf. set the master server to 1, that is, server-id = 1.
Modify the log-bin attribute in my. cnf. for example, you can set it to log-bin =/home/china/mysql-bin.
Slave server (slave) configuration. Www.bitsCN.com
Modify the server_id attribute in my. cnf to be different from the master server, for example, server-id = 2.
After logging on to MySQL, enter change master to master_host = 'master _ IP', master_port = 3306, master_user = 'username', master_password = 'password' on the command line ';
Run the start slave command to start the slave thread.
After completing the preceding configuration, we can view the master status on the master server and run the show master status command;
Similarly, we can also view the slave server status on the slave server, show slave status;
After completing the above configuration, we have completed the configuration of the MySQL master/slave server. now let's verify:
Switch to the test database on the master server and execute SQL, create table userInfo (id int, name varchar (20 ));
Run the show tables command to check whether the table userInfo has been created.
At this time, we can see from the server that the userInfo table should have been created.
At the same time, if we want to insert data in the table userInfo of the master server, the slave server will also insert data automatically.
If the slave server does not synchronize the data of the master server and check the slave server status, an error message is displayed:
"Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'could not find first log file name in binary log index file '"
This is because the data on the master and slave servers is not synchronized. you can perform the following steps:
Run the stop slave command on the slave server to stop the slave server.
Use the command flush logs on the master server to refresh the log information of the master server.
Run the show master status command on the master server to view the status of the master server. focus on the log file name and position offset ).
On the slave server, run the command change master to master_log_file = 'MySQL-bin.00004 ', master_log_pos = 397. Note that the file name and position correspond to the master server.
Run the start slave command to start the slave thread of the slave server.
If you insert data into the master server table again, the data can be synchronized normally.
BitsCN.com