Whether you're backing up your work, migrating data, or collaborating with other teams, being able to confidently export or import your MySQL or MariaDB database is a must-have skill. This guide walks you through both processes cleanly, clearly, and safely.
Exporting (or "dumping") a database creates a .sql
file that contains all your database content, which you can later import elsewhere.
mysqldump -u [username] -p [database_name] > [backup_file.sql]
Example:
mysqldump -u root -p my_database > my_database_backup.sql
-u
: The database user.-p
: Prompts for the password.> backup_file.sql
: Output file where data will be saved.đź’ˇ Tip: Add
--single-transaction
for large databases to ensure consistency during the dump.
Importing is just the reverse taking a .sql
file and loading it into a database.
mysql -u [username] -p [database_name] < [backup_file.sql]
Example:
mysql -u root -p my_database < my_database_backup.sql
Make sure the database you're importing already exists. If not, create it first:
mysql -u root -p -e "CREATE DATABASE my_database;"
Prefer a web interface? If you're using phpMyAdmin, follow these steps:
.sql
file → Click Go.⚠️ File upload size limits may apply. Modify your
php.ini
if needed.
scp
or rsync
with SSH to transfer .sql
files between servers..sql
file for faster and safer transfers:gzip my_database_backup.sql
To decompress:
gunzip my_database_backup.sql.gz
Managing MySQL or MariaDB databases doesn’t have to be complicated. Whether you’re creating backups or migrating to a new server, exporting and importing are essential processes. Use the CLI for full control or phpMyAdmin for a user-friendly interface either way, you’re in command.
Want to focus on what you do best while we handle the tech?
👉 Contact us today and elevate your data infrastructure with expert hands.