How To Import and Export Databases in MySQL or MariaDB

Import and Export database is an important part while we are working with any project with database. We can use data exported database for backup or restoration.

Export the Database

mysqldump -u username -p databasename > dump.sql

Above command will create a dump.sql file for your database and it will be generated in the current directory in which you run mysql dump command.

Import the Database

To Import database you should have one database or you can create one with below command.

mysql -u root -p
mysql> CREATE DATABASE databasename; //create a new database

mysql> exit; //exit from MySql Shell Prompt.

Below command will be going to import your dump.sql file to newly created or your existing database. Make sure about your dump.sql file path should be correct.

mysql -u username -p databasename < dump.sql

Leave a Reply

Your email address will not be published. Required fields are marked *