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: For more exciting articles, please follow the help houseProgramming TutorialTopic.