How to create a MSDOS Batch Script to restore many .sql database ?


I would like to request an assistant.

May i know how to create a MSDOS Batch Script to restore many .sql database ?

FYI, all the .sql file which have been previously backup located at C:\DatabaseBackups\20090414_115405 folder.

I would like to restore all this mysql using a script because it have hundreds of .sql file.

Appreciates if anybody can help me.

Thank you.
Who is Participating?
theGhost_k8Database ConsultantCommented:
Put this where all SQL files are stored. It will load one by one sql files to mysql

### loadsql.bat ####

echo off
for /f "tokens=*" %%a in ('dir /b *.sql') do  mysql -uUSER -pPASSWORD < %%a
For windows, you can create a php file (one that will be run in command line) that reads .sql backup files through the directory and runs it to restore the databases(use exec() function for this). Then you can create the batch file to run the php file in command line.
Let me know if you have trouble with the code. :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.