Taking the backup of the database is necessary whether it small or large projects. You can easily revert the database if something went wrong.
Using phpMyAdmin you can easily export your MySQL database but it got cancel if it exceeds the max defined time.
You can also Command-Line to export selected MySQL database.
In this tutorial, I am using XAMPP in windows.
Contents
1. Export Database
- I am exporting
tutorial
database using Command-Line.
- For this open Command Prompt.
- Navigate to
xampp/mysql/bin
folder.
- Execute the following command –
Syntax –
mysqldump -u username -p database-name > export-file-name.sql
username – MySQL username.
database-name – Database name which you want to export.
export-file-name.sql – Specify you export file name.
Example –
mysqldump -u root -p tutorial > tutorial.sql
Here, I am exporting tutorial
database and set export file name – tutorial.sql
.
It will ask for a password.
Enter the user password if you have defined otherwise press enter.
A new SQL file will create in the xampp/mysql/bin/
folder.
2. Export table
If you want to export specific tables instead of whole database then you can use below command –
Syntax –
mysqldump -p --user=[username] [databasename] tablename1 tablename2 ... > export-file-name.sql
Example (Export single table) –
mysqldump -p --user=root webinar tutorial country > tutorial.sql
- Here, I am exporting
country
table fromtutorial
database, and set export file name –tutorial.sql
. - It will ask for a password.
- Enter the user password if you have defined otherwise press enter.
- A new SQL file will create in the
xampp/mysql/bin/
folder.
Example (Export multiple tables) –
mysqldump -p --user=root webinar tutorial country userinfo > tutorial.sql
- Here, I am exporting
country
anduserinfo
tables fromtutorial
database, and and set export file name –tutorial.sql
.
3. Conclusion
You can either export your MySQL database using phpMyAdmin or Command-Line.
The SQL file stored in xampp/mysql/bin/
folder if you have used the command line.
With Command-Line you can also import SQL file in your MySQL database.
If you found this tutorial helpful then don't forget to share.