MySQL Database implements master-slave synchronization data
Reference Links:
Http://www.cnblogs.com/wxf020412/archive/2007/09/25/905628.html
http://369369.blog.51cto.com/319630/790921
1. Description
Data synchronization is achieved using the data synchronization mechanism of the database itself, which can also be implemented by backing up the database directory and through third-party synchronization tools.
2. Prepare two + MySQL databases
①, best version consistent
3. Primary database Configuration
①, open mysql configuration file (Windows)my.ini or (Linux, typically in /etc/mysql/ directory)my.cnf
Under the mysqld node, configure the following:
[Mysqld]
# Master-Slave database data synchronization, a single configuration of a database synchronization, not write back the entire database
Binlog-do-db=refrigrator
# must be turned on
Log-bin=mysql-bin
#id, must , uniquely identify the server, typically The last byte of IP
server-id=203
②, turn on Master mode, authorize slave
# master server
GRANT REPLICATION SLAVE on * * to ' myaccount ' @ '% ' identified by ' 123456 ';
%: As long as the account password is correct can be used as the primary server slave, can be specific IP
③, command-line Input command: Displays the status of the primary database
Show Master status;
4, from the database configuration
①, in the mysqld node under the following configuration:
[Mysqld]
# Master-Slave database data synchronization, a single configuration of a database synchronization, not write back the entire database
# from database, query operation
replicate-do-db = Refrigrator
# open log, not required
Log-bin = Mysql-bin
# must, identify the server unique ID
Server-id =
②, turn on master-slave mode, configure this server to slave server
# from server
Change Master to
Master_host= ' 10.10.107.203 ', master_user= ' MyAccount ', master_password= ' 123456 ', master_log_file= ' mysql-bin.000002 ', master_log_pos=107;
Must be the same as the primary database Position,flie (show master status meaning)
③, check the state of slave:show slave status;
MySQL database implements master-slave synchronization data