mysql - 如何在 bash/mysql 脚本中引用 .my.cnf 的位置?

标签 mysql bash

我有一个连接到 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/

相关文章:

php - 将 AJAX JSON 与 PHP/MySQL 结合起来? php ://input?

mysql - 显示数组时出错

python - 我如何制作一个带有 argparse 的 Python3 文件来读取文件的内容?

bash - 如何在 ssh 命令行中使用环境模块?

linux - Grep:复制包含特定文本的链接

bash - 使用 UNIX Bash 脚本将文件名中的外来字符替换为等同的英文字符

php - 使用 PHP 和 MySQL 存储用户图像的最佳方式是什么?

php - iPhone xCode 插入 mySQL

java - Android Studio 如何将我的项目与 mySQL db 连接(新闻提要应用程序)

node.js - 加载共享库 : libgtk-x11-2. 0.so.0 时出错: