Export and Import Database in CentOS/Ubuntu Server

We can easily export and import MySQL/MariaDB database in CentOS or Ubuntu server.


  1. SSH access to Linux sever.
  2. The database credentials.

Export Database

Login to your server via SSH. You need the database name, username of the database and the user password. Now run this command to export the database:

sudo mysqldump -u USERNAME -pPASSWORD DATABASE_NAME > database_name.sql
  • USERNAME – The username of the database.
  • PASSWORD – The password of the user. 
  • DATABASE_NAME – The database name you want to export. 
  • database_name.sql – This will be the exported .sql file which will be stored in the current directory (the SSH server’s current path).

At the time of exporting, if there is any problem, mysqldump will print the error.


sudo mysqldump -u obydul -pTest1234 test_db_1 < dump.sql

Import Database

Login to the database as root (or root access username).

mysql -u root -p

We are going to create a new database called 'new_database'.

CREATE DATABASE new_database;

Exit the MySQL by typing CTRL+D.

Now go to the directory where the .sql file is located. Then hit this command to import the database:

sudo mysql -u USERNAME -pPASSWORD new_database < database_name.sql
  • USERNAME - The username of the new database.
  • PASSWORD - The password of the user. 
  • new_database - The database name where you want to import. 
  • database_name.sql - This database will be imported.


sudo mysql -u obydul -pTest1234 test_db_2 < dump.sql

You can learn more from official mysqldump documentation page. Thank you.