Restore MySQL database in WampServer

If you are running WampServer on your local machine, it can be a bit tricky to restore a MySQL database. You need to do it from the Windows command line (DOS prompt), rather then the MySQL console command line. The actual MySQL restore command is slightly different to normal and you need to make sure you are in the right directory first.

Here are the steps (using WampServer 2.0):

  1. Go to the Windows command line by going to Start -> Run and typing in cmd.
  2. You need to change directory to the MySQL bin directory. On my version, the directory is c:\wamp\bin\mysql\mysql4.1.22\bin.
    Therefore, the command to change to this directory is:

    cd wamp\bin\mysql\mysql4.1.22\bin
  3. Put the MySQL dump (SQL file) into the above directory
  4. Create the new database in phpmyAdmin (or on the command line)
  5. The actual restore command is slightly different to normal. The command is:
    mysql.exe -u root -p databasename < filename.sql

    Note that is says mysql.exe rather than the normal mysql.

  6. When it asks you for a password, just hit enter. There is no password assocated with the database that you created (unless you prefer to have one. But as it is local, there is no need)
  7. That's it!

Enjoy this article?

Get my best content on Javascript, CSS, PHP & Git before anyone else and special bonuses.

Get started

Comments

I am a unix guy and could not for the life of me figure out how to run shell commands with windose cmd, thanks so much!

Blair Wadman's picture

No problem Bri, glad to help!

dynamite! really helped

Hey! Thanks a lot for this bit of advice, really useful and couldn't find anything else on the internet that actually explains this!

Thanks. You are the best! I have been searching the Net for days to no avail.

Excellent peace of help. Thank you

Perfect ! thanks for your help

Thanks VERY VERY much - took ages to find this but it does exactly what it says on the tin. One of those magic results that don't happen very often

Nice

thxs man ,

Thanks man, this helps me a lot. I have been searching this for a quite a while.

Can I use the above procedure to restore a existing database where the file name of the database to be restored is "databasename.bak" ?

Email me please: clsoemail@gmail.com

Blair Wadman's picture

Yes you should be able to. If the database dump is databasename.bk, then it would be:

mysql.exe -u root -p databasename < databasename.bk

This was just what I was looking for but it doesn't seem to work.

I get a message in the command window that says "mysql.exe is not recognized as an internal or external command, operable program or batch file".

Any suggestions?

Thanks!

Please disregard my prior message as I screwed up (I'm a bit of a newb).

It worked well once i figured out my problem.

Thanks for your help.

Blair Wadman's picture

Glad you got it working! :)

You save my life!!

Add new comment