For small business website design and development. Most of common platform is use php and mysql database.in this tutorial I will explain how you can take dump file and restore database using command line (cmd).
Dumping and Restoring MySQL databases on the Windows command prompt is a simple process.
in windows 10 find with cmd then you can see this screen then right click on the command prompt select Run as Administration.
If MySQL has been added to your Windows path variable, If you open a
mysql command in first time you can see image is like this. It will show error. Check the image link below.
your computer just needs to know the location of MySQL to run MySQL-related commands. You tell Windows this location by adding the MySQL directory to your path variable. using the Windows GUI in a different post. But in the spirit of going commando, let’s add MySQL’s location to the Windows path variable using the command prompt.
- In your Windows command prompt, execute the command:
set path=C:\path\to\mysql\executable, where C:\path\to\mysql\executable corresponds to the location of the mysql.exe file on your machine. I am running MySQL version 5.6.12, which was bundled with WAMP at my time of my download. So, the MySQL executable is located in
- After you have added MySQL’s location to your Windows path variable, you should test the
mysqlcommand. Below is a screenshot of MySQL being added to the Windows path variable and the
mysqlcommand tested on my machine.
mysql is recognized in the Windows command prompt, you can run the MySQL commands listed below to dump and restore your databases.
To dump/export a MySQL database, execute the following command in the Windows command prompt:
mysqldump -u username -p dbname > filename.sql. After entering that command you will be prompted for your password. Once the password is entered your dump file will be available in the root directory for your Windows user – ie:
C:\Users\username. An example is shown in the screenshot below.
To restore/import a MySQL database, execute the following command in the Windows command prompt:
mysql -u username -p dbname < filename.sql. After entering that command you will be prompted for your password. Once the password is entered your dump file that exists in the root directory for your Windows user will be restored. An example is shown in the screenshot below.
We have successfully dumped and restored a MySQL database using the Windows command prompt.