MySQL Master/Slave Server Configuration

Source: Internet
Author: User

The configuration of the master server (master) is simple. You only need to modify the two parts 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.2cto.com modify my. modify the server_id attribute in cnf to be different from the master server. For example, after logging on to MySQL with server-id = 2, enter change master to master_host = 'master _ ip' in the command line ', master_port = 3306, master_user = 'username', master_password = 'Password'; Use the start slave command to start the slave thread. After the above configuration, we can view the master status on the master server, and use the command show master status; www.2cto.com, we can also view the slave server status on the slave server, show slave status; after the above configuration is complete, we have completed the configuration of the MySQL Master/slave server. Now let's verify that we 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, the following 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' "is caused by data synchronization between the master and slave servers. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.