Synchronization of MySQL master to standby with scripting (one increment per five minutes)

Source: Internet
Author: User

    1. target : The main library data (IP1) sync to standby every five minutes (IP2) sync increase only

    2. ideas :

    3. use crontab Timed execution of the script every five minutes for data synchronization

    4. compile in script to implement query data increase in five minutes , implementation process and code ( with record ):

    5. Bash contents in script

      VI transaction.sh----CREATE transaction script to implement synchronization

      #!/bin/bash

Source.bash_profile

( you need to add the environment variable in bash because the timed execution function is implemented using crontab)

Exportid= ' mysql-n-utest-ptest\[email protected]#$-dtest-e ' Select

Max (transaction_id) from record "'

( use alternate variable ID to define the current maximum transaction_id value in the repository)

Mysql-n-hip2-uslaveroot-p7pyw#7ahh7-dtest-e "Use

test;select* from record where transaction_id > $ID ;" > Backup.sql

(Finding a value greater than transaction_id in the Main library is the amount of data growth in the record in that five minute and importing it

to the backup.sql file )

Sed-i ' S#null#\\n#g ' Backup.sql

( error in import due to character set problem "null", using sed directives to replace NULL as \ n)

Mysql-n-utest-ptest\[email protected]#$-dtest-e "Use Test;load datainfile

'/home/mysql/backup.sql ' into table record;

( Import the generated backup.sql file )

crontab Script Writing

crontab-e ( edit timed script )

5,10,15,20,25,30,35,40,45,50,55* * * */home/mysql/transaction.sh

( executes transaction.sh every five minutes )

    1. The results of the implementation test

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5A/02/wKioL1Tz4jWSXGaiAAC9WrRequ0816.jpg "style=" float: none; "title=" 1.png "alt=" Wkiol1tz4jwsxgaiaac9wrrequ0816.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5A/06/wKiom1Tz4STTqRp1AACrfbrAP5Q098.jpg "style=" float: none; "title=" 2.png "alt=" Wkiom1tz4sttqrp1aacrfbrap5q098.jpg "/>

This article is from the "Sunny" blog, make sure to keep this source http://dbasunny.blog.51cto.com/9192126/1616432

Synchronization of MySQL master to standby with scripting (one increment per five minutes)

Related Article

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.