3 回答

TA贡献1802条经验 获得超5个赞
如果您的MySQL客户端/服务器版本是5.6.xa以避免警告消息的方式,请使用mysql_config_editor工具:
mysql_config_editor set --login-path=local --host=localhost --user=username --password
然后,您可以在shell脚本中使用:
mysql --login-path=local -e "statement"
代替:
mysql -u username -p pass -e "statement"

TA贡献1813条经验 获得超2个赞
我用类似的东西:
mysql --defaults-extra-file=/path/to/config.cnf
要么
mysqldump --defaults-extra-file=/path/to/config.cnf
config.cnf包含:
[client]
user = whatever
password = whatever
host = whatever
这使您可以拥有多个配置文件-用于不同的服务器/角色/数据库。使用〜/ .my.cnf仅允许您进行一组配置(尽管这可能是一组有用的默认值)。
如果您使用的是基于Debian的发行版,并且以root身份运行,则可以跳过上述内容,而只需使用/etc/mysql/debian.cnf即可进入...:
mysql --defaults-extra-file=/etc/mysql/debian.cnf
添加回答
举报