MySQL 实用程序 - ~/.my.cnf 选项文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16299603/
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
MySQL Utilities - ~/.my.cnf option file
提问by Carlton
I am trying to use 2 of the mysql utilities, mysqldiff and mysqldbcompare and want to avoid putting my password on the command line
我正在尝试使用 2 个 mysql 实用程序,mysqldiff 和 mysqldbcompare,并希望避免将我的密码放在命令行上
Is it possible to use an option file to specify the password for my DB connection to prevent me having to specify the password?
是否可以使用选项文件为我的数据库连接指定密码以防止我必须指定密码?
This is the sort of command that I currently have...
这是我目前拥有的那种命令......
/usr/share/mysql-workbench/python/mysqldiff --server1=root@localhost --server2=root@localhost --difftype=sql db1:db2
I also have a file at ~/.my.cnf that has "600" permissions and contains the following..
我在 ~/.my.cnf 处也有一个文件,该文件具有“600”权限并包含以下内容..
[client]
user=root
password=mypassword
When I connect via the command line to MySQL it picks up the details in my option file but the mysql utilities don't :-/
当我通过命令行连接到 MySQL 时,它会在我的选项文件中获取详细信息,但 mysql 实用程序不会:-/
回答by Retraut
Try this -
尝试这个 -
[client]
user=root
password="pass"
[mysql]
user=root
password="pass"
[mysqldump]
user=root
password="pass"
[mysqldiff]
user=root
password="pass"
Location for .my.cnf: ~/.my.cnf
.my.cnf 的位置: ~/.my.cnf
Please refer to the manual page entitled Using Option Files
请参阅标题为“使用选项文件”的手册页
回答by mimoralea
To enhance on @Retraut's answer get your passwords in quotes. The accepted answer wouldn't work if you have special characters in your password, which by the way, is good security practice.
要增强@Retraut 的回答,请将您的密码用引号括起来。如果您的密码中有特殊字符,那么接受的答案将不起作用,顺便说一下,这是一种很好的安全做法。
[client]
user=root
password="p@$$"
[mysql]
user=root
password="p@$$"
[mysqldump]
user=root
password="p@$$"
[mysqldiff]
user=root
password="p@$$"
http://dev.mysql.com/doc/refman/5.7/en/option-files.html
http://dev.mysql.com/doc/refman/5.7/en/option-files.html
Search for "Here is a typical user option file:" and see the example they state in there. Good luck, and I hope to save someone else some time.
搜索“这是一个典型的用户选项文件:”并查看他们在那里陈述的示例。祝你好运,我希望能拯救别人一些时间。