MySQL Database believes that everyone has put into production. Many people integrate him and PHP in Apache, serving Website. Indeed, they are more applications in Website, and phpMyAdmin is the best application example of PHP MySQL. So mysql can achieve two systems to copy the database through TCP / IP? Can you realize real-time copy? That is to say, you can implement synchronization (SYNCHRONIZATION). Firstly, you will now introduce Mysql's Replication Database feature. Replication is similar to the copy database to another server, but it is to ensure complete synchronization of the two databases by defining the relationship between Master and Slave. This feature begins in the mysql version 3.23. Let's take a test of MySQL's Replication. The author's platform is: Master: MySQL 3.23.53-log on FreeBSD 4.7 Release IP: 192.168.10.100slave: mysql 3.23.56-log on freebsd 4.8 Stable IP: 192.168.10.200 1, master machine set permissions, giving Slave Right rights And package the database structure to be synchronized. Masterbsd # pwd / usr / local / mysql / binmasterbsd #. / Mysql -u root -penter password: welcome to the mysql monitor. Commands end with; or /g.Your mysql connection ID is 2 to Server Version: 3.23.53- Log type 'help;' or '/ h' for help. type '/ c' to clear the buffer.mysql> grant file on *. * to replication@192.168.10.200 identified by 'repplan; 192.168.10.200 Is the slave machine with file permission), then package the database masterbsd # cd varmasterbsd # tar czvf repdatabase.tar.gz repdatabase, the package file repdatabase.tar.gz2 set the primary server Master's My.TAR.GZ2 set the master server master. Start the mysql service masterbsd # vi /etc/my.cnf Add or modify the following [mysqld] log-bin server-id = 1 sql-bin-update-SamebinLog-do-db = repdatabase to the RepDatabase library The Replication function then restarts the Mysql of the master master server. Masterbsd # / usr / local / mysql / bin / mysqladmin -u root -p ShutdownMasterBSD # / usr / local / mysql / bin / safe_mysqld --user = mysql & 3, establishing a Slave database Just now we package repdatabase.tar in Master. GZ, its role is to restore the same database in slave. First pass the master's repdatabase.tar.gz file to the SLAVE machine.
Then Slavebsd # tar zxvf repdatabase.tar.gz -c / usr / local / mysql / var / 4, modify the slet server's my.cnf slavebsd # vi /etc/my.cnf Add or modify the following Master- host = 192.168.10.100master-user = replicationmaster-password = replicationmaster-port = 3306server-id = 2master-connect-retry = 60replicate-do-db = reldatabase [database to be updated] log-slave-updates5, restart the Slave Slave Start. SLAVEBSD # / usr / local / mysql / bin / mysqladmin -u root -p shutdownsd # / usr / local / mysql / bin / safe_mysqld --user = mysql & 6, test first detect whether the repdatabase in the two mysql database is normal. Normal conditions should be the same repDatabase database in Master and Slave, and the data inside. Then we test whether the replication function is on.