How to synchronize data between two MySQL Databases

Source: Internet
Author: User
MySQL Database Synchronization is required during development. The two systems with the same installation are FreeBSD5.4 and Apache2.0.55 and PHP4.4.0. the MySQL version is 4.1.15, which is the latest version. 1. install and configure the two servers and install MySQL respectively in the usrlocalMySQL directory (the installation steps are omitted, refer

MySQL Database Synchronization is required during development. The two systems with the same installation are FreeBSD5.4, and Apache 2.0.55 and PHP 4.4.0 are installed. The MySQL version is 4.1.15, which is the latest version. 1. install and configure the two servers, and install MySQL respectively in the/usr/local/MySQL directory (the installation steps are omitted, refer

MySQL Database Synchronization is required during development. The two systems with the same installation are FreeBSD5.4, and Apache 2.0.55 and PHP 4.4.0 are installed. The MySQL version is 4.1.15, which is the latest version.

1. Install the configuration

Install MySQL on both servers in the/usr/local/MySQL directory (the installation steps are omitted. Refer to the relevant documentation ), the IP addresses of the two servers are 192.168.0.1 and 192.168.0.2. We use 192.168.0.1 as the master database and 192.168.0.2 as the slave server. We adopt one-way synchronization, that is, the master data is the master data, then, slave takes the initiative to sync data back from the master.

The configuration of the two servers is the same, we copy the key configuration file, the default configuration file is in the/usr/local/MySQL/share/MySQL directory, there are my-large.cnf, respectively, my-medium.cnf, my-small.cnf and so on several writers, we just test, use my-medium.cnf on the line. After MySQL is installed, the default configuration file is specified in the database storage directory. We use 4.1.X, therefore, the configuration file should be in the/usr/local/MySQL/var directory, so you can copy the configuration file:

Cp/usr/local/MySQL/share/MySQL/my-medium.cnf/usr/local/MySQL/var/my. cnf

The two servers perform the same copy configuration file operation.

2. Configure the Master server

We need to configure 192.168.0.1 as the primary MySQL Server (master), so we need to consider that we need to synchronize that database and use that user for synchronization. Here we will use the root user for synchronization for the sake of simplicity, in addition, you only need to synchronize the database abc.

Open the configuration file:

Vi/usr/local/MySQL/var/my. cnf

Find the information:

# Required unique id between 1 and 2 ^ 32-1 # defaults to 1 if master-host is not set # but will not function as a master if omittedserver-id = 1 // 1 for master, 2 is salve

Add two rows:

SQL-bin-update-same // synchronous form binlog-do-db = abc // database to be synchronized

Restart the MySQL server of 192.168.0.1:

/Usr/local/MySQL/bin/MySQLadmin shutdown/usr/local/MySQL/bin/MySQLd_safe -- user = MySQL &

3. Configure the Slave server

Our slave server mainly takes the initiative to synchronize data back from the master server. We edit the configuration file:

Vi/usr/local/MySQL/var/my. cnf

Note: More exciting articles, please pay attention to SanlianProgramming TutorialTopic.

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.