How to Save a Database with MySQLDump in WAMP?

August 10, 2016 / Database
Summary

Today, we will learn how to save a MySQL database on a Windows environment, after installing a web server WAMP. We will use a native tool that comes with MySQL i.e. MySQLDump.

In this tutorial, we are going to use WAMP 2.5 and will name the backup as “mydb”.

Database Saving

We will have to open a Windows command prompt. Building on the executable “mysqldump” then can quickly back up a database.

cd "C: \ wamp \ bin \ mysql \ mysql5.6.17 \ bin \"
mysqldump.exe -u root -p mydatabase> C: \ Backup \ mabase.sql
Enter password: ****************

We jump by assigning the directory where the executable file located and then mysqldump.exe with the –u option to the user name, –p option to be asked for the password, and following your options as it is necessary to indicate the name of the database. Then the end of the line records the output to a file named “mabase.sql” located in the directory “C:\Backup”.

The download has to enter the password every time. Which is not a practical thing to perform the backup through a script. Hence, we will see a better alternative.

At the root of the “C” drive, create a file “my.cnf” with the following content tailoring information:

[Mysqldump]
user = user
password = password

Save this file, this also be positioned at the following locations from the documentation of mysqldump:

- C: \ WINDOWS \ my.cnf 
- C: \ wamp \ mysql \ my.cnf

On this file, please limit by security permissions. And specify permissions for the accounting system and the account that is running WAMP on your server.

Finally, the option is removed “-p” command, since it will necessary to specify a password, it will refer directly to the my.cnf

cd "C: \ wamp \ bin \ mysql \ mysql5.6.17 \ bin \"
mysqldump.exe -u root mydatabase> C: \ Backup \ mabase.sql

The backup should run without intervention from you to enter the password!

To script all, you can add the date in the name of the file, save it in a script file Batch, and run by a scheduled task.