MySQL 通过批处理脚本运行mysql脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8830773/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 22:20:27  来源:igfitidea点击:

Run mysql script by batch script

mysqlbatch-file

提问by nikel

I've searched for hours, there are many posts or tutorials but I couldn't run my batch script.

我已经搜索了几个小时,有很多帖子或教程,但我无法运行我的批处理脚本。

on dos prompt this code works fine:

在 dos 提示下,此代码工作正常:

-u root -h localhost -p******** siir_07 dumper.sql

but this gives error with batch:

但这会导致批处理出错:

"c:\program files\mysql\mysql server 5.5\bin\mysql.exe" "-u root -h localhost -p******** siir_07 dumper.sql"

the error is:

错误是:

ERROR 1045 (28000): Access denied for user ' root -h localhost -p**siir_07 dumper.s'@'localhost' (using password: NO)

错误 1045 (28000):访问被拒绝用户 'root -h localhost -p* *siir_07 dumper.s'@' localhost '(使用密码:NO)

回答by Timur

Z:\test.bat :

Z:\test.bat :

Z:\webserver\mysql\bin\mysql.exe -u test -p test < test.sql

When I run it from command line, everything is OK. So, try to remove quotes and redirect input using <.

当我从命令行运行它时,一切正常。因此,尝试删除引号并使用<.

回答by HKumar

You can also use source to execute sql script for example

例如,您还可以使用 source 来执行 sql 脚本

 mysql -u%DBUSERNAME% -p%USERPASSWD% -D%DBNAME% -e "source something.sql;"

回答by Akavall

This solution worked for me:

这个解决方案对我有用:

mysql -u my_username -D my_database -p < test.sql

After this I got a prompt to enter my password, I did and everything worked.

在此之后,我得到了输入密码的提示,我做到了,一切正常。

回答by newtover

you should redirect input from file using <and remove extra spaces:

您应该使用<并删除额外的空格从文件重定向输入:

mysql -uroot -p*** < dumper.sql

I would also suggest putting the username password, and most probabry charset parameters in a separate INI file and use it as follows:

我还建议将用户名密码和大多数可能的字符集参数放在单独的 INI 文件中,并按如下方式使用它:

 mysql --defaults-extra-file=myconf.ini < dumper.sql

回答by David Chan

it thinks this is your username

它认为这是你的用户名

' root -h localhost -p** siir_07 dumper.s'

try changing the quotes around in your batch script

尝试更改批处理脚本中的引号