我有一个连接到 mysql 服务器并提取信息的 bash 脚本。我的主目录中有 .my.cnf 文件。我想将 .cnf 文件的位置更改为 ~myname/.my.cnf
我的问题是如何在我的脚本或对数据库的 mysql 调用中引用这个新位置?
谢谢
最佳答案
以下是有关 MySQL 如何查看选项文件的文档引用: https://dev.mysql.com/doc/refman/5.7/en/option-files.html
File Name Purpose
/etc/my.cnf Global options
/etc/mysql/my.cnf Global options
SYSCONFDIR/my.cnf Global options
$MYSQL_HOME/my.cnf Server-specific options (server only)
defaults-extra-file The file specified with --defaults-extra-file, if any
~/.my.cnf User-specific options
~/.mylogin.cnf User-specific login path options (clients only)
注意:您想使用defaults-extra-file
与 mysql 客户端连接时的选项。 mysql --defaults-extra-file=~/path/to/file/.filename < script
您应该考虑使用--login-path
作为备选。 Login path reference 。该文件不是纯文本。您使用mysql_config_editor
创建您的登录路径,其中存储用户名、密码、主机等。
关于mysql - 如何在 bash/mysql 脚本中引用 .my.cnf 的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46159521/