How to Export Database in MySQL From the Command Line
This tutorial explores the concept of exporting a database using the command line in MySQL.
Export Database in MySQL From the Command Line
Many-a-times, it becomes important for businesses and organizations to export a database when they migrate, copy, store or share a database. MySQL helps us get this done using the command line.
In this tutorial, we will learn how to route our command line to the bin directory in MySQL and how to export a database.
We will divide this tutorial into three steps.
- Open the command prompt.
- Go to the bin directory.
- Write the command to export the database.
We begin by opening the command prompt using the Windows+R key. This key would trigger Windows to open run, as shown in the following picture.
Now, we type cmd
in our run box to open the command prompt.
Once the command prompt opens, we need to direct ourselves into the root directory of MySQL; it would give access to our MySQL server.
It can be done with the command below (make sure to change the below command with your MySQL’s bin directory).
cd C:\wamp\bin\mysql\mysql5.1.36\bin
Within our server, we need to export our database. It can be done using the following command.
mysqldump -u user_name -p database_name > wantedsqlfile.sql
In this case, we use the following query (assuming that root
is the username, the password is empty, and the database name is boatdb
).
mysqldump -u root -p boatdb > file_Name.sql
The image shows that the file is generated when we put the password. It can be visualized with the help of the following image.
Thus, with the help of mysqldump
and set path
commands, we can easily export any database using the command line.