How to import and export MySQL database?

How to import and export MySQL database?

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.




  1. Import MySQL database
  2. 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. 

Command: mysql -u root -p

1.2. Next, you will have to run a query in order to create a new database called new_database.

Query: CREATE DATABASE new_database;

1.3. Then exit out of the DBMS.

Query: exit;

1.4. As soon as you return into your server command line you can start importing the database dump file.

Command: mysql -u root -p new_database < data-dump.sql

Note: 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.

Command: mysqldump -u root -p new_database > data-dump.sql




You have successfully imported and exported your databases in your MySQL DBMS.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.