Mysql master-slave Database Synchronization

Source: Internet
Author: User

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

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.