问题描述
我正在尝试以非交互方式将密码传递给gcloud sql connect命令.我想要实现的不是要求输入密码,而是以某种方式在命令中传递密码.
I am trying to pass the password to gcloud sql connect command in a non-interactive way. What I want to achieve is not being asked for password, but pass it in the command somehow.
根据文档,不确定是否可行,但是另一方面,自动化任务非常有用,我坚信有一种方法可以做到...
Not sure if it's possible, based on documentation, but on the other hand it's something very useful to automate tasks, I strongly believe that there is a way to do it...
命令:
gcloud sql connect <database_name> --user=<user_name>
推荐答案
gcloud sql connect
提供了糖"以方便连接到Cloud SQL实例.我认为(!)不接受密码的原因是这样可以更容易地破坏密码.
gcloud sql connect
provides "sugar" to facilitate connecting to Cloud SQL instances. I assume (!) that the reason for it not accepting passwords is that passwords could be more easily compromised this way.
如果要针对实例编写脚本,则首选的机制是让您使用适当的[MySQL | PostgreSQL]客户端连接到数据库实例,使用客户端进行身份验证并以这种方式运行脚本.
If you want to script against an instance, the preferred mechanism would be for you to use the appropriate [MySQL|PostgreSQL] client to connect to your database instance, authenticate using the client and run your scripts that way.
HTH
这篇关于如何以非交互方式为gcloud CLI传递数据库密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!