Replicate MySQL database once per day

Posted on 2012-08-13
Last Modified: 2012-08-13
I have a MySQL database that we use for IDS systems.  We would like to create a second database in a remote location and replicate DB1 with DB2.  I found plenty of information about setting up database replication with MySQL, but it seems they are do replication in near real time.

Is there a way I can set up replication to only take place at night?  This would help reduce stress to our WAN link.


Both databases would be running on RHEL6.
Question by:savone
    LVL 7

    Expert Comment

    You could make an initial dump and play it into the second database server. Then once per day you run "flush logs" and script-copy the latest binary log file  to the second server and import it there.
    LVL 24

    Accepted Solution

    Use the same replication setup, but just turn it off when you don't want it to run.  Have cron  jobs that will call the following:

    When you want it to start replicating:
    mysql -u root -proot_password -e "start slave"

    When it's time to stop replicating:
    mysql -u root -proot_password -e "stop slave"

    You may want to put those to shell scripts so that you don't put the passwords in the crontab.  Also, might be helpful to do some checks before stopping the slave by calling "show slave status\G" then grep the "Seconds_Behind_Master" line - check if the value is zero to make sure that that slave has fully caught up with the master.  In my setup it usually takes an hour to catch up with a day's worth of transaction.
    LVL 24

    Expert Comment

    multimac's solution will also work, but it involves multiple steps including transferring of binary logs.  I see it has one advantage though - once you run the binary logs you know you're done - unlike the master-slave replication where you need to check the status.
    LVL 23

    Author Comment


    So I would put those script on the slave server correct?
    LVL 24

    Expert Comment

    Yes that's correct.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
    Read about achieving the basic levels of HRIS security in the workplace.
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now