开发者

how to write a bat file to execute the .sql file

I want to execute a query inside a db.sql file using MySQL 5.1 in the Windows env开发者_如何学编程ironment. Can any one help me with this? I want to do this by running a .bat file.


Col Shrapnel's answer is the way to do it. The batch file would look like this:

mysql < %1

...which really just shows that it'd just be easier to use that directly instead of a .bat.

runsql myfile.sql  // (assuming you name your batch file "runsql.bat")
// vs
mysql < myfile.sql

Reading your comment on the other answer, it seems like you might actually get some use out of the batch file as long as you don't mind storing your password in plain text on your computer.

Make the batch file like this:

mysql -u myusername -pmypassword < %1

Note that there is no space between -p and mypassword. If you use that above, every script would have to specify which database to use, which might be a hassle. The other way you could do it is like this:

mysql -u myusername -pmypassword -D %1 < %2

And the usage would be:

mysql database_name input.sql


mysql.exe < db.sql
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜