Export and Import Database in CentOS/Ubuntu Server
We can easily export and import MySQL/MariaDB database in CentOS or Ubuntu server.
Prerequisites
- SSH access to Linux sever.
- 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. ?
Comment
Preview may take a few seconds to load.
Markdown Basics
Below you will find some common used markdown syntax. For a deeper dive in Markdown check out this Cheat Sheet
Bold & Italic
Italics *asterisks*
Bold **double asterisks**
Code
Inline Code
`backtick`Code Block```
Three back ticks and then enter your code blocks here.
```
Headers
# This is a Heading 1
## This is a Heading 2
### This is a Heading 3
Quotes
> type a greater than sign and start typing your quote.
Links
You can add links by adding text inside of [] and the link inside of (), like so:
Lists
To add a numbered list you can simply start with a number and a ., like so:
1. The first item in my list
For an unordered list, you can add a dash -, like so:
- The start of my list
Images
You can add images by selecting the image icon, which will upload and add an image to the editor, or you can manually add the image by adding an exclamation !, followed by the alt text inside of [], and the image URL inside of (), like so:
Dividers
To add a divider you can add three dashes or three asterisks:
--- or ***

Comments (0)