Cloud House Technologies Logo
CloudHouse Technologies
HomeServicesProjectsBlogAbout UsCareersContact UsLogin
    Cloud House Technologies Logo
    CloudHouse Technologies
    HomeServicesProjectsBlogAbout UsCareersContact UsLogin

    How to Migrate MySQL/MariaDB Databases Between Servers: mysqldump, rsync & Replication Guide

    Priya

    Content Writer & Researcher

    Last Updated: 29 June 2026
    How to Migrate MySQL/MariaDB Databases Between Servers: mysqldump, rsync & Replication Guide
    🖥️

    Migrating a Production MySQL Database? Don't Risk Data Loss

    Database migrations are high-stakes — a wrong command can corrupt InnoDB tablespaces or leave your application pointing at stale data. CloudHouse Technologies handles MySQL and MariaDB migrations with replication-based zero-downtime cutovers and full post-migration validation.

    🔧 Book Free DiagnosisCall NowWhatsApp
    🖥️12,400+PCs Fixed
    ⭐4.9★Google Rating
    ⚡<15 minAvg. Response
    🛡️ISO 27001Certified

    Migrating MySQL or MariaDB databases between servers is one of the most common — and highest-risk — tasks in a server move. Get it wrong and you face data loss, downtime, or corrupted tables. This guide covers three production-tested methods: mysqldump for full exports, rsync for fast binary transfers, and MySQL replication for near-zero downtime cutover.

    Pre-Migration Checklist

    Before moving any database, complete this checklist to avoid surprises mid-migration:

    • MySQL/MariaDB version compatibility: Confirm the destination server runs the same or a newer version. Downgrading MySQL version is not supported.
    • Character set and collation: Run SHOW CREATE DATABASE dbname; on the source — note the character set and collation for re-creation on the destination.
    • Storage engine: Confirm InnoDB is available on the destination. MyISAM tables require special handling for binary transfers.
    • Available disk space: Ensure the destination has at least 2× the source database size (dump file + imported data).
    • User privileges: Export your MySQL users and grants with pt-show-grants or a manual query (covered below).
    • Firewall rules: If migrating via direct replication, open port 3306 between source and destination temporarily.

    💡 None of these worked? Skip the guesswork.

    Get Expert Help →

    Method 1: mysqldump — Full Database Export and Import

    mysqldump is the standard tool for database migration when downtime is acceptable or databases are small enough to export quickly.

    1Export all databases from the source server
    mysqldump -u root -p   --all-databases   --single-transaction   --routines   --triggers   --events   --master-data=2   --flush-logs   > /root/full-backup-$(date +%F).sql

    Flag breakdown:

    • --single-transaction: Consistent snapshot for InnoDB without locking tables
    • --routines: Includes stored procedures and functions
    • --triggers: Includes triggers (default: on, but explicit is safer)
    • --events: Includes scheduled events
    • --master-data=2: Records the binary log position (needed if setting up replication later)

    To export a single database:

    mysqldump -u root -p --single-transaction --routines --triggers mydb > mydb.sql
    2Transfer the dump to the destination server
    rsync -avz --progress /root/full-backup-*.sql root@destination-ip:/root/

    Or with SCP:

    scp /root/full-backup-*.sql root@destination-ip:/root/
    3Import on the destination server
    mysql -u root -p < /root/full-backup-*.sql

    For large dumps, use screen or tmux to prevent disconnection from killing the import:

    screen -S db-import
    mysql -u root -p < /root/full-backup-*.sql
    # Ctrl+A, D to detach — reconnect with: screen -r db-import
    4Monitor import progress
    # In a second session, check current database size growth
    watch -n5 'mysql -u root -p -e "SELECT table_schema AS db, ROUND(SUM(data_length+index_length)/1024/1024,1) AS MB FROM information_schema.tables GROUP BY table_schema ORDER BY MB DESC LIMIT 10;"'
    1Identify the MySQL data directory
    mysql -u root -p -e "SELECT @@datadir;"
    # Typically: /var/lib/mysql/
    2Initial rsync (while source MySQL is running)
    rsync -avz --progress /var/lib/mysql/ root@destination-ip:/var/lib/mysql/

    This pre-syncs the bulk of data. Run multiple times to reduce the delta.

    3Stop the source MySQL, final sync, start destination MySQL
    # Source server: stop MySQL
    systemctl stop mysql
    
    # Final delta sync
    rsync -avz --delete /var/lib/mysql/ root@destination-ip:/var/lib/mysql/
    
    # Destination server: fix ownership and start
    chown -R mysql:mysql /var/lib/mysql/
    systemctl start mysql
    4Verify databases are present on destination
    mysql -u root -p -e "SHOW DATABASES;"
    Warning: Binary data directory transfers only work reliably between identical MySQL/MariaDB versions and the same OS architecture (64-bit to 64-bit). Using this method across different versions risks InnoDB tablespace corruption.
    1Enable binary logging on the source server

    Add to /etc/mysql/mysql.conf.d/mysqld.cnf (or /etc/my.cnf):

    [mysqld]
    server-id = 1
    log_bin = /var/log/mysql/mysql-bin.log
    binlog_do_db = mydb   # omit to replicate all databases
    systemctl restart mysql
    2Create a replication user on the source
    mysql -u root -p
    CREATE USER 'replicator'@'destination-ip' IDENTIFIED BY 'StrongPass123!';
    GRANT REPLICATION SLAVE ON *.* TO 'replicator'@'destination-ip';
    FLUSH PRIVILEGES;
    3Export a consistent snapshot and note the binary log position
    mysqldump -u root -p --all-databases --single-transaction --master-data=2 > /root/snapshot.sql
    # The --master-data=2 flag writes the log position as a comment at the top of the dump
    head -30 /root/snapshot.sql | grep "MASTER_LOG"
    # Example: -- CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000003', MASTER_LOG_POS=1234;
    4Import the snapshot on the destination
    mysql -u root -p < /root/snapshot.sql
    5Configure the destination as a replica
    mysql -u root -p
    CHANGE MASTER TO
      MASTER_HOST='source-server-ip',
      MASTER_USER='replicator',
      MASTER_PASSWORD='StrongPass123!',
      MASTER_LOG_FILE='mysql-bin.000003',
      MASTER_LOG_POS=1234;
    START SLAVE;
    6Monitor replication lag
    SHOW SLAVE STATUS\G
    # Watch "Seconds_Behind_Master" — when it reaches 0, replication has caught up
    7Cutover: redirect application to destination

    Once Seconds_Behind_Master = 0:

    • Put the application in maintenance mode or set the DB to read-only on source: FLUSH TABLES WITH READ LOCK;
    • Update the application's database host to the destination IP
    • Run STOP SLAVE; on the destination
    • Remove the read lock on the source: UNLOCK TABLES;
    • Verify the application connects successfully

    Migrating MySQL Users and Permissions

    Database user grants are not always included in a standard mysqldump. Export them explicitly:

    mysql -u root -p -e "SELECT CONCAT('SHOW GRANTS FOR ''', user, '''@''', host, ''';') FROM mysql.user WHERE user != '';" | mysql -u root -p | grep -v "Grants for" | sed 's/$/;/' > /root/mysql-users.sql

    Or use Percona Toolkit's pt-show-grants for a cleaner output:

    pt-show-grants --user=root --password=your-password > /root/grants.sql

    Import on the destination:

    mysql -u root -p < /root/mysql-users.sql
    FLUSH PRIVILEGES;

    Post-Migration Validation

    After completing the migration, validate data integrity before decommissioning the source:

    # Count rows in critical tables on both servers
    mysql -u root -p -e "SELECT COUNT(*) FROM mydb.orders;"
    
    # Compare table checksums (run on both servers — hashes should match)
    mysqlcheck -u root -p --all-databases --check-only-changed
    
    # Check for InnoDB errors
    mysql -u root -p -e "SHOW ENGINE INNODB STATUS\G" | grep -A5 "LATEST FOREIGN KEY ERROR\|LATEST DETECTED DEADLOCK"

    Run your application's test suite against the destination database before cutting over production traffic.

    If you need expert assistance migrating a large or complex MySQL database with zero downtime, CloudHouse Technologies' server migration service handles database migration, replication setup, and post-cutover validation as part of a complete server move.

    FAQs

    Get the Free Linux Server Admin Cheatsheet (PDF)

    Essential commands for server management, networking, and troubleshooting — all on one printable page.

    Running Linux servers? Let us manage them for you.

    Our Managed Linux Server plans cover updates, security hardening, monitoring, and 24/7 incident response — so your servers stay up and your team stays focused.

    • Proactive OS patching and security updates
    • 24×7 monitoring with instant alerting
    • Backup configuration and disaster recovery
    • Dedicated Linux engineers on call
    See Pricing Plans →

    What our customers say

    “Our production server went down at 2 AM. CloudHouse had it back online in under 20 minutes. Incredible response time.”

    Arun S.

    CTO, SaaS Startup

    “They migrated our entire infrastructure from Ubuntu 18 to 22 with zero downtime. Couldn't have asked for better.”

    Deepak N.

    DevOps Lead

    Frequently Asked Questions

    A 10GB mysqldump typically takes 5–20 minutes depending on disk I/O speed, the number of tables, and whether --single-transaction is used (which adds slight overhead for InnoDB). Transfer time via rsync depends on network speed between servers. On a 1Gbps network, transferring 10GB takes about 2–3 minutes.

    Book your free 15-minute diagnosis

    A certified technician will call you back within 15 minutes during business hours.

    Share this article

    Leave a Comment

    Comments (0)

    Loading comments...

    Need Help With Your MySQL Server Migration?

    Large database migrations require careful planning, replication setup, and validation to avoid data loss or extended downtime. CloudHouse Technologies specialises in server migration — we manage the entire database transfer process so you can migrate with confidence.

    Call Now — FreeWhatsApp Us

    Why CloudHouse?

    • ISO 27001:2022 certified
    • 12,400+ devices supported
    • 4.9★ on Google
    • Sub-15-minute response

    CloudHouse Technologies

    Innovative cloud solutions for modern businesses. We deliver cutting-edge technology with exceptional service.

    Contact Us

    CloudHouse Technologies Pvt.Ltd
    Special Economic Zone(SEZ),
    Infopark Thirissur,4B-15,
    Indeevaram,Nalukettu Road,
    Koratty, Kerala, India-680308
    0480-27327360
    info@cloudhousetechnologies.com

    Quick Links

    • Our Services
    • Gold Loan Software
    • About Us
    • Contact
    • Terms and Conditions
    • Privacy Policy
    ISO27001:2022
    Certified

    © 2026 CloudHouse Technologies Pvt.Ltd. All rights reserved.

    Back to top