07.06.2023

How to export and import MySQL databases

What is DB export/import purposes

You may need to export or import your database upon regular backup operations, moving project to another server, disaster recovery operations etc.

Methods for database export

Actual server control panels may provide possibilities to export and import database data. E.g. in aapanel you click to Databases link, then create database backup and download it;

If your server has PHPMyadmin, you can use it for DB-export. Just login to PHPMyadmin as user with permissions for "manage" database, click to the DB-name, then Export tab and Go button;

But even if no any GUI-features possible, you can export database via SSH-console. Authorize on the server, then run:

mysqldump db_name > /path/db_name.sql

How to import database

To import database via server management panel you can click to Databases link, then Import > Upload from local, select dump file on your computer and press to Import;

Also, you can import dump via PHPMyadmin. Login, click to the database name, then Import, choose dump file and click to Go button:

And of course, you can import DB dump via SSH. Just run:

mysql -udb_username -p dbname < /path/to/dump.sql

Then type your password.

 

Conclusion

In this article I explained why you could need to save or restore your database and how to do this in a few ways.