π How to Transfer a Database Between VPS Servers
When moving a website or project to a new VPS, itβs crucial to properly transfer your database. Mistakes can cause data loss or service downtime. This guide explains safe ways to migrate MySQL and PostgreSQL databases.
π¦ Method 1: MySQL/MariaDB Transfer via Dump
- π€ On the old server, run:
mysqldump -u root -p dbname > dump.sql - π Copy the dump to the new VPS:
scp dump.sql user@new-server:/home/user/ - π₯ Import on the new server:
mysql -u root -p dbname < dump.sql - β Verify that all data and structure are restored correctly
π Method 2: PostgreSQL Database Transfer
- π€ Create the dump:
pg_dump -U postgres dbname > db.sql - π Copy the file to the new VPS:
scp db.sql user@new-vps:/home/user/ - π₯ Import the dump:
psql -U postgres dbname < db.sql - π Make sure the database and user exist before importing
π Alternative: Transfer Physical Files via rsync
- β Only use if both servers have the same DB version
- π§ Stop the database:
systemctl stop mysqlorsystemctl stop postgresql - π¦ Copy files:
rsync -avz /var/lib/mysql/ user@new-vps:/var/lib/mysql/ - π Ensure correct permissions and ownership
- βΆ Start the database and check logs for issues
π Best Practices
- π Always make a backup before migration
- π Avoid using insecure protocols to transfer dump files
- π€ Ensure character sets match between source and destination
- π§© Check CMS or application compatibility with DB version
If you're unsure how to safely migrate your database, contact Bit.Hosting support. We can assist or perform the transfer for you! π