MySQL master-Slave synchronization configuration

Source: Internet
Author: User
Tags unique id rsync

File synchronization rsync synchronization http://www.cnblogs.com/itech/archive/2009/08/10/1542945.html in the current production work, most applications MySQL master-slave synchronization is asynchronous replication mode, That is, data synchronization is not strictly real-time. Real-time and asynchronous: When the master-slave replication is configured, all updates to the database content must be made on the primary server to avoid conflicts with updates to the database content on the server that are inconsistent with the database content on the server. So why do all the updates have to be done on the master server? How do we make sure that users are updated on the master server? By sending an email or verbally telling the developer to agree that mom won't write it from the library, or is there another way to do it? In fact, there may be a lot of methods, below we give you one way. From the technical means to let the developer can not write, but not the agreement not to let him write.   (1) The master-slave server is the backup of the master-slave server architecture, which can greatly enhance the robustness of the database architecture. For example, when there is a problem with the primary server, we can switch manually or automatically (http://oldboy.blog.51cto.com/2561410/1240412) to continue the system service from the server. This is similar to NFS storage data that is synchronized to the backup via Inotify+rsync, except that the MySQL synchronization scheme is its own tool. Non-human hardware, service failure, for the thought of the implementation of Drop,delete powerless. (2) master-slave server read-write separation share site pressure the master-slave server architecture can read and write the user (client) request through the program (Php/java) or proxy software (Mysql-proxy,amoeba), that is, by simply processing the user's Select query request from the server, Reduce user query response time and the pressure of reading and writing colleagues on the primary server. The updated data (update, INSERT, delete) is still given to the primary server for processing, ensuring that the primary server and the server remain in real-time synchronization. If the site is non-update (to browse mainly) mainly business, such as blog,www home display and other services, query requests more, this is from the server's reading and writing load balance is very effective, this is the legendary read and write separate database structure in large companies: Through the program (PHP, java) test environment: Agent Software (MSYQL-PROXY,AMOEBA) Portal: Distributed Dbproxy (read/write separation, hash load balancing, health check)  mysql master-slave copy implementation today say how MySQL Master-slave replication to do! Preparation: 1. Two virtual machines: I use the CENTOS5.5,IP address is 192.168.1.101 and 192.168.1.105; 101 master server, 105 do slave server (both have installed the same version of MySQL); 2. Native Environment:apache+php+mysql  Well, let's get started. Take a look at this sounds tall on the master-slave copy is going on.   principle: MySQL to achieve master-slave replication, in fact, relying on the binary log, that is: Assume that the main server called a, from the server called B; master-slave replication is   B followed by a study, a do what, b do what. So how does B synchronize the action of a? Now A has a log function, the actions of their own additions and deletions   all recorded in the log, b just need to get this log, according to the log above the action on their own body can be. This enables the master-slave replication.   Extension: MySQL also has a log called: Slow log    can set a time, then all execution time exceeds this time of SQL will be recorded. This allows the slow log to quickly find the SQL bottleneck in the site to optimize.           There's time for you to look into it, and there's not much to do about it.   Implementation steps: 1. First modify the MySQL configuration file to support the binary logging feature. Open the MySQL profile for the primary server: my.conf code: # VI/ETC/MY.CNF Add the following three lines of code: Parameter explanation: Log-bin=mysql-bin  //name mysql binary log mysql-bin   binlog_format=mixed//binary log format, there are three kinds: statement/row/mixed, specifically not to do more explanation, here Use mixed   server-id=101// Set a unique ID for the server to differentiate, here use the last one of the IP address to act as server-id  configuration complete,: Wq save, restart MySQL restart MySQL command: # service mysqld Restart the same, enter from the server, Configure the MY.CNF from the server, repeat step 1, the only difference is that the Server-id to be changed from the server IP tail, that is server-id=105, the other two are the same, save, and restart Mysql; 2. Assign an account to the server from the primary server, like a key, and take the key from the server to share the primary server's log files. Mys into the primary serverQL Interface, command: # mysql-u root-p 111111    //I am here MySQL account is root, password is 111111 under the MySQL interface, enter the following line command: GRANT replication slave O N * * to ' slave ' @ '% ' identified by ' 111111 ';   3. View the information for the primary server bin log (these values are logged after execution, and then do not do anything to the primary server until you have finished configuring the slave server. Because these two values change each time the database is manipulated.  4. Set the MySQL command from server to server: # mysql-u root-p111111  Close Slave (if you have previously configured master and slave, be sure to close first) command: Stop slave;  Start configuration: Enter the following code: Parameter interpretation: Master_host  :   Set the IP address of the primary server to connect   Master_user  :   Set the username   Master_password &nbsp for the primary server you want to connect to:   Set the password for the primary server to connect     Master_log_file  :   Set the The log name of the primary server's bin log, which is the 3rd step to get the information     Master_log_pos  :   Sets the record location of the bin log for the primary server to connect to, that is, the information obtained in step 3rd, (note that The last item does not need to be quoted. Otherwise the configuration fails)   starts from server configuration, starting from server: command: Start slave; 5. To see if the configuration was successful: command: Show slave status;  The above two items are Yes, indicating that the configuration was successful, otherwise, Please repeat the previous steps.  ok, here MySQL master and slave copy is configured, in fact, understand the principle is still very simple.    

MySQL master-slave synchronization configuration

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.