从命令行使用 sql 身份验证的 sqlcmd

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2358191/
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-09-01 05:32:25  来源:igfitidea点击:

sqlcmd from command-line with sql authentication

sqlcommand-linesqlcmd

提问by chama

SQLCMD uses windows authentication by default. According to the MSDN documentation, you can change it by adding a -U parameter to the command and then the user name.

SQLCMD 默认使用 Windows 身份验证。根据MSDN 文档,您可以通过在命令中添加 -U 参数然后添加用户名来更改它。

The problem is with the password. Is there any way to access the sql server if the password is blank?

问题出在密码上。如果密码为空,有没有办法访问sql server?

sqlcmd -U admin
password:

Whenever I try this and just press enter (indicating that the password is an empty string), I get a message saying that the login failed.

每当我尝试此操作并按回车键(表示密码为空字符串)时,我都会收到一条消息,提示登录失败。

Any suggestions? thanks

有什么建议?谢谢

回答by James Holland

This forum post http://social.msdn.microsoft.com/Forums/en-US/sqlsecurity/thread/15e4a7c0-6547-44e8-9e25-4f14c12570caimplies that sqlcmd does not support empty passwords. The workaround is to use osql.

这个论坛帖子http://social.msdn.microsoft.com/Forums/en-US/sqlsecurity/thread/15e4a7c0-6547-44e8-9e25-4f14c12570ca暗示 sqlcmd 不支持空密码。解决方法是使用 osql。

However the documentation for sqlcmd heresuggests you can use a blank password:

但是,此处的 sqlcmd 文档建议您可以使用空白密码:

"If the -U option is used and the -P option is not used, and the SQLCMDPASSWORD environment variable has not been set, sqlcmd prompts the user for a password. If the -P option is used at the end of the command prompt without a password sqlcmd uses the default password (NULL)."

"如果使用了-U 选项而未使用-P 选项,并且未设置SQLCMDPASSWORD 环境变量,则sqlcmd 会提示用户输入密码。如果在命令提示符末尾使用-P 选项而没有密码 sqlcmd 使用默认密码 (NULL)。”

Hope one of those helps you!

希望其中之一对您有所帮助!