Knowledgebase: Database > MySQL
How to mirror MySQL databases
Posted by Chris S., Last modified by Sabi D. on 16 December 2015 08:20 AM

Mirroring MySQL databases with mysqldump
We will use mysqldump to synchronize your mirror and production server databases.

  1. Before running mysqldump, you will need to create an empty MySQL database on mirror/destination server

  2. Create a database user and assign it rights over the above database (If mirroring you can user the same name, credentials as on source/production server).

  3. Login to destination server via SSH using a ssh client like Putty or WinSCP.

  4. If using a control panel at source/production server, ensure Remote MySQL connections to source database are allowed (In cPanel add % at cPanel > Databases > Remote MySQL > Add an Access host)  

  5. Test MySQL connections (port 3306) source database are open (could be blocked at source or destination firewall). At SSH console window type
    mysql -uproductionDBname -p -P 3307 -h productionIP
  6. If you have large database or slow/poor network connection, in SSH console window run command
    screen
  7. Now in text editor build the sync command using the following syntax after replacing blue and green terms with actual values;

    mysqldump -h productionIP -u productionMySQLuser -p'productionPassword' productionDBname | mysql -h mirrorIP -u mirrorMySQLuser -p'mirrorPassword' mirrorDBname 

    1. productionIP - the IP address of your production/source server
    2. productionMySQLuser - the MySQL user on your production/source server
    3. productionPassword - the password for your MySQL user on your production/source server 
      (type your password immediately after typing the "-p" no spaces)
    4. productionDBname - name of the production/source server database that you want to backup
    5. mirrorIP - the IP address of your mirror/destination server
    6. mirrorMySQLuser - the MySQL user on your mirror/destination server (you will need to create this user via your mirror CPanel)
    7. mirrorPassword - the password for the MySQL user on your mirror/destination server
    8. mirrorDBname - the database you are backing up to on your mirror/destination server (destination database will need to created before running mysqldump)

  8. Finally in SSH console window with screen running, paste the sync command with actual values and press enter.

Once the process complete, your destination database will be a mirror of the source database. 

(143 vote(s))
Helpful
Not helpful

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).