Md. Obydullah Howdy, I am Md. Obydullah from Bangladesh. I love to write the article which will help others. It's my passion.

Export and Import Database in CentOS/Ubuntu Server

Published on May 25, 2019 55 sec read

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

Prerequisites

  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.

Example:

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.

Example:

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

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

Md. Obydullah Howdy, I am Md. Obydullah from Bangladesh. I love to write the article which will help others. It's my passion.

Leave a Reply

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