开发者

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

开发者 https://www.devze.com 2023-01-01 03:24 出处:网络
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 answ

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

精彩评论

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

关注公众号