我的目标是能够在无需提示输入密码的情况下启动命令。有什么办法可以从 Windows 命令行实现这一点?在 Linux 中,我觉得我可以将密码发送到标准 in 或其他东西,但我不确定我是否可以为 Windows 执行此操作。
谢谢!
最佳答案
有两种方式:
- 设置环境变量 PGPASSWORD 例如
设置 PGPASSWORD=您的 secret 密码
- 使用密码文件
%APPDATA%\postgresql\pgpass.conf
,如 documentation 中所述
在密码文件中(我的位置是 C:\Users\Grzesiek\AppData\Roaming\postgresql\pgpass.conf)使用指定的 doc 格式。例如连接数据库 postgres 作为本地 5432 服务器上的角色 postgres 添加:
localhost:5432:postgres:postgres:12345
我检查过这个并且它工作正常(对我来说),但不要使用 127.0.0.1。
关于Windows PSQL 命令行 : is there a way to allow for passwordless login?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6216432/