我可以为多个 mysql 命令行调用输入一次密码,其中查询是未知的吗? [英] Can I enter password once for multiple mysql command line invocations, where the queries are not known upfront?

查看:45
本文介绍了我可以为多个 mysql 命令行调用输入一次密码,其中查询是未知的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以通过将查询放入文件来避免重新输入 mysql 命令行密码.

You can avoid re-entering mysql command line password by putting the queries into a file.

在我的情况下,直到第一个查询完成后才确定后面的查询.

In my case, the later queries are not determined until after the first queries have finished.

这发生在非交互式脚本中,因此运行 mysql 控制台不是一种选择.

This happens in a non-interactive script so running a mysql console is not an option.

是否有用于 mysql 命令行交互的会话的概念?或者我可以将它设置为侦听本地 unix 套接字上的命令(需要返回输出)?或者类似的东西?

Is there any notion of a session for mysql command line interactions? Or can I set it up to listen for commands on a local unix socket (the output is required to be returned)? Or something like that?

推荐答案

用户@smcjones 提到使用 .my.cnf 文件或 mysql_config_editor.这些都是很好的建议,我给他 +1 票.

User @smcjones mentions using the .my.cnf file or mysql_config_editor. Those are good suggestions, I give my +1 vote to him.

另一种解决方案是将凭据放在您选择的任何文件中,然后在调用 MySQL 工具时指定该文件:

Another solution is to put the credentials in any file of your choosing and then specify that file when you invoke MySQL tools:

mysql --defaults-extra-file=my_special.cnf ...other arguments...

最后,为了完整起见,您可以将环境变量用于某些选项,例如主机和密码.但奇怪的是,不是用户.参见 http://dev.mysql.com/doc/refman/5.7/en/environment-variables.html

And finally, just for completeness, you can use environment variables for some options, like host and password. But strangely, not the user. See http://dev.mysql.com/doc/refman/5.7/en/environment-variables.html

export MYSQL_HOST="mydbserver"
export MYSQL_PWD="Xyzzy"
mysql ...other arguments...

我真的不建议使用环境变量作为密码,因为任何可以在您的客户端主机上运行 ps 的人都可以看到 mysql 客户端进程的环境变量.

I don't really recommend using an environment variable for the password, since anyone who can run ps on your client host can see the environment variables for the mysql client process.

这篇关于我可以为多个 mysql 命令行调用输入一次密码,其中查询是未知的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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