Mysql implements master-slave Synchronization

Source: Internet
Author: User

Mysql implements master-slave synchronization in mysql to achieve master-slave synchronization: Step 1: install one mysql on each of the two machines (my testing machine system is unbutu, mysql5.5 ), if there is only one machine, the mysql port must be different (3306, 3307 ). Step 2: Find the mysql my. cnf file. $ Cd/etc/mysql to enter the directory. $ Vim my. cnf is read-only and cannot be modified. $ Sudo vim my. step 3 of cnf: modify my. configuration items in cnf: 1 the following operations must be performed: change bind-address = 127.0.0.1 to bind-address = 0.0.0.0 and remove the comment (#) for # server-id = 1 # log_bin =/var/log/mysql/mysql-bin.log. Add: character-set-server = UTF-8 # ensure consistent encoding. After filling in, save and exit. Step 4: log on to and create a Server Load balancer instance with the root permission: $ mysql-uroot-p mysql> grant replication slave, replication client on *. * to liang @ '2017. 168.10.21 'indntified by 'shanghai'; mysql> grant replicatin slave on *. * to liang @ '2017. 168.10.21 'indntified by 'shanghai'; Step 5: restart the mysql service. $ Sudo/etc/init. d/mysql restart # if it cannot be started normally, check the configuration items of my. cnf and mysql error logs. Error log location:/var/log/mysql/error. log has completed the master configuration. Slave configuration. Step 6: Modify the my. cnf configuration file of slave. As follows: bind-address = 0.0.0.0 server-id = 2master-host = 192.168.10.24master-user = liangmaster-password = liangmaster-port = 3306log_bin =/var/log/mysql/mysql-bin.loglog-slave-updatesskip-slave-start character-set-server = utf8 save and exit. step 7: restart the mysql server of slave (same as step 5). I encountered an error during restart and cannot start mysql. after checking the log, we found that the following error (temporarily omitted) is not on the local machine because the error log is not on the local machine. Make up later, hey. The configuration is changed to the following: server-id = 2 # master-host = 192.168.10.24 # master-user = liang # master-password = liang # master-port = 3306log_bin =/var/log/mysql/mysql-bin.loglog-slave-updatesskip-slave-start character- set-server = utf8 save and restart mysql, OK. go to myslq and run slave start in mysql. Step 8: Run mysql> show master status \ G in master. The displayed content is as follows: Step 9: In slave, run the following command: mysql> change master to master_host = '2017. 168.10.24 ', master_user = 'Li Ang ', master_password = 'liang', master_log_file = 'mysql-bin.000007 ', master_log_pos = 170; master_log_file and master_log_pos are shown in Step 8. mysql> slave start; Step 10: execute the following command in the master: mysql> show slave status \ G; check Slave_IO_Running: YES Slave_ SQL _Running: YES OK. The configuration is successful. Please see Slave_IO_Running: Connectiong. Please view the following error information or log files. Step 2: Test the creation of a database in the primary database: mysql> create database ccc; view it in slave. If the ccc database exists, the synchronization is successful. You can also create tables, modify tables, and add records. Everything is OK. Finally, thank you for your friends on the Internet. With your help, you can easily complete the process.

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.