Detailed description of mysql master-slave synchronization in windows, mysql master-slave

Source: Internet
Author: User

Detailed description of mysql master-slave synchronization in windows, mysql master-slave

When I first heard that the program supports read/write splitting, I have never been exposed to Java.

When an occasional opportunity is reached, you must remember it.

Let's talk about the master-slave synchronization of databases today. There are two advantages:

  • Yes. read/write splitting can be used. For example, the write operation is written to the master database, and the read operation is read from the slave database.
  • Back up the database purely to prevent the hard disk from crashing.

Master/Slave database operation preparation:

Mysql 5.5 and later versions are installed on both computers. It is recommended that both computers install the same database version and can be used independently.

Remember the IP addresses of the two computers:

Take my home computer as an example: master database: 192.168.0.102 slave Database: 192.168.0.104

Primary database operations]

Step 1:

Find the my. ini file in the installation directory of the primary database mysql and add the master server configuration under mysqld.

Server-id = 1 # server id log-bin = C: \ Program Files \ MySQL Server 5.5 \ mysql-bin # binary file storage path binlog-do-db = test1 # database to be synchronized

After saving and restarting the mysql service, you can see the mysql-bin.index file and mysql-bin.000001 file under C: \ Program Files \ MySQL Server 5.5

Enter the username and password: mysql-u username-p password (mysql-uroot-proot)

Step 2,

Set permissions for the slave server to be connected: grant replication slave, reload, super on *. * to slave@192.168.0.104 identified by 'root ';

Ps: add permissions to host 192.168.0.104, Username: slave, password: root; (you only need to enter the permission once)

Step 3,

Enter the command show master status; # record the values of File and Position;

Operate from database]

Step 4:

Find the my. ini file in mysql and add the slave server configuration under its [mysqld:

Server-id = 2 # server id, which cannot be the same as the master server's replicate-do-db = test1 # database to be synchronized

Save and restart the mysql Service

Step 5:

Test mysql-u slave-p root-h 192.168.0.102 on the server to check whether the connection to the master database is successful,

Enter exi to exit mysql command line or close the cmd window to open a new cmd

Step 6:

Modify the connection parameters of the primary database: mysql> change master to master_host = '2017. 168.0.104 ', master_user = 'slave', master_password = 'root', master_log_file = 'mysql-bin.000001 ', master_log_pos = 107; (replace the entered mysql-bin.000001 and 107 here with the value queried in step 3 otherwise it will not be synchronized)

Ps: An error may be reported, which means that the slave thread is running and cannot be set. In this case, execute mysql> stop slave; stop the slave thread, and then set the connection parameters;

Step 7:

After setting, run mysql> start slave; enable the slave thread; execute mysql> show slave status \ G (no semicolon) to view

Slave_IO_Running: Yes
Slave_ SQL _Running: Yes

This is a detailed step. If it fails, please contact me for help. Follow this step as long as the two computers are interconnected over the network, there should be no problem.

Note that:

If you modify the slave database, it will not be synchronized to the master database, so you should use the master-master synchronization method, similar,

Therefore, insert and delete update operations should be performed on the master database, while select operations on the slave table.

How to Implement read/write splitting in a specific program will be presented in a specific demo in the future

The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!

Related Article

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.