How to Export and Import MySQL with phpMyAdmin or the Command Line
- Ali GhanimatiAuthor
- Last updated
- 2 minutesReading time
- 1,493Views
- Ali Ghanimati
- Last updated:
- 2 min read
- 1,493 views
A database export lets you move a site or recover its content independently of the application files. For a small database, phpMyAdmin is convenient. Command-line tools are more practical when web uploads time out or the dump is large.
Confirm the database name, credentials, size, and destination before starting. Import into a new or backed-up database. A dump may contain statements that replace tables, and it does not normally transfer users or privileges.
Export and import with phpMyAdmin
Choose the source database, open Export, and use SQL format. Review tables and compression in Custom mode if you need them. On the destination, create or select the target database, open Import, and upload the file. If you hit upload or execution limits, use the command line or ask your host. phpMyAdmin import and export.

Use mysqldump and mysql
Run these commands in a trusted shell, using separate credentials for each database. Enter passwords at the prompts. Add the provider’s hostname when the database is remote.
mysqldump --single-transaction --no-tablespaces -u source_user -p source_db > backup.sql
mysql -u target_user -p target_db < backup.sqlThe transaction option gives a consistent view for transactional tables such as InnoDB. Prevent schema changes during the dump and plan how to handle nontransactional tables or active writes. Check any required routines, events, and database engine or character set differences. MySQL mysqldump reference.
Check the restore log, table counts, and representative records. Connect the application and test a read and a write before switching production.


