This tutorial explains how to import and export MySQL databases. Importing and exporting MySQL databases is useful when creating and restoring backups of your databases for websites or any other database related projects.
- MySQL database.
- Import MySQL database
- Export MySQL database
1. Import MySQL database
To import an existing database dump file into your MySQL (MariaDB) DBMS (DataBase Management System), you will first have to create the new database. You will import the contents of the database dump file into the new database.
1.1. First, log into your MySQL DBMS as root. Enter your root user password and you will log into the MySQL DBMS shell prompt.
mysql -u root -p
1.2. Next, you will have to run a query in order to create a new database called
CREATE DATABASE new_database;
1.3. Then exit out of the DBMS.
1.4. As soon as you return into your server command line you can start importing the database dump file.
mysql -u root -p new_database < data-dump.sql
data-dump.sql is the database dump file, which you are importing into the MySQL DBMS.
2. Export MySQL database
Export your MySQL database into a *.sql file.
mysqldump -u root -p new_database > data-dump.sql
You have successfully imported and exported your databases in your MySQL DBMS.