Mysql master-slave Database Synchronization explanation master server settings 1. Create a replication user with the replication slave permission [SQL] mysql> grant replication slave on *. * to 'repl' @ '192. 168.1.22 'identified by 'repl'; 2. Edit the master server my. cnf file [plain] Server-id = 1 # host id, integer log-bin =/var/log/mysql/mysql-bin.log # Make sure this file can be written read-only = 0 # host, both read and write operations can be Binlog-do-db = test # data needs to be backed up. Multiple read and write operations can be separated by commas (,), such as test1, test2 Binlog-ignore-db = mysql # databases that do not need to be backed up 3. Set the read lock [SQL] mysql> flush tables with read lock; 4. Get the binlog Log File Name and offset [SQL] mysql> show master status; 5. Back up the database to be synchronized [SQL] mysqldump test> test. SQL 6. unlock [SQL] mysql> unlock tables; slave server settings 1. Edit slave server my. cnf file [plain] server-id = 2 log_bin =/var/log/mysql/mysql-bin.log master-host = 192.168.1.100 # is the master server IP address master-user = slave <span style = "font-family: arial, Helvetica, sans-serif; ">#</span> <span style =" font-family: Arial, Helvetica, sans-serif; "> User name used to synchronize data with the master server, after configuring the master server, we have added slave </span> master-pass = 123456 master-port = 3306 # master server port master-connect-retry = 60 # If the slave server the master server is disconnected, time Difference of reconnection (seconds) replicate-do-db = test # only copy a database replicate-ignore-db = mysql # do not copy a database 2. start the slave server slave thread [SQL] mysql> start slave; 3. Verify in host A, mysql> show master status \ G; in slave B, mysql> show slave status \ G; see the following content File: mysql-bin.000001Position: 1374Binlog_Do_DB: testBinlog_Ignore_DB: mysql