如何写一个bat文件来执行.sql文件 [英] how to write a bat file to execute the .sql file

查看:50
本文介绍了如何写一个bat文件来执行.sql文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Windows 环境中使用 MySQL 5.1 在 db.sql 文件中执行查询.谁能帮我这个?我想通过运行 .bat 文件来做到这一点.

I want to execute a query inside a db.sql file using MySQL 5.1 in the Windows environment. Can any one help me with this? I want to do this by running a .bat file.

推荐答案

Col Shrapnel 的答案是解决方案.批处理文件如下所示:

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

mysql < %1

...这实际上只是表明直接使用它而不是 .bat 会更容易.

...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

注意 -pmypassword 之间没有空格.如果你使用上面的,每个脚本都必须指定要使用的数据库,这可能很麻烦.另一种方法是这样的:

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

用法是:

mysql database_name input.sql

这篇关于如何写一个bat文件来执行.sql文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆