[英]how do I reference location of .my.cnf in bash/mysql script?
我有一個連接到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)
注意:與mysql客戶端連接時,要使用defaults-extra-file
選項。 mysql --defaults-extra-file=~/path/to/file/.filename < script
您應該考慮使用--login-path
作為替代方案。 登錄路徑參考 。 該文件不是純文本。 您可以使用mysql_config_editor
創建您的登錄路徑,該路徑存儲用戶名,密碼,主機等。
我不知道您所說的“〜myname / .my.cnf”是什么意思。 這將擴展到由用戶名和“ myname”串聯而成的目錄,這沒有任何意義。 我猜你可能是說“〜/ something / .my.cnf”
'〜' 擴展為$ HOME,因此只需在調用mysql之前就重新定義$ HOME就足夠了(盡管這會使對'〜'的進一步引用產生混淆。
HOME=$HOME/myname
mysql <somescript.sql
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.