[英]For homebrew mysql installs, where's my.cnf?
對於自制 mysql 安裝,my.cnf 在哪里? 它安裝一個嗎?
默認情況下沒有 my.cnf。 因此,MySQL 以所有默認設置啟動。 如果您想創建自己的 my.cnf 來覆蓋任何默認值,請將其放在 /etc/my.cnf。
此外,您可以運行mysql --help
並查看列出的 conf 位置。
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf
The following groups are read: mysql client
The following options may be given as the first argument:
--print-defaults Print the program argument list and exit.
--no-defaults Don't read default options from any option file.
--defaults-file=# Only read default options from the given file #.
--defaults-extra-file=# Read this file after the global files are read.
如您所見,還有一些選項可以繞過 conf 文件,或者在命令行上調用 mysql 時指定要讀取的其他文件。
自制 mysql 在安裝的 support-files 文件夾中包含示例配置文件。
ls $(brew --prefix mysql)/support-files/my-*
如果您需要更改默認設置,您可以使用其中之一作為起點。
cp $(brew --prefix mysql)/support-files/my-default.cnf /usr/local/etc/my.cnf
正如@rednaw 指出的那樣,MySQL 的自制安裝很可能位於/usr/local
中,因此不應將 my.cnf 文件添加到系統/etc
文件夾中,因此我更改了將文件復制到/usr/local/etc
中的命令/usr/local/etc
。
如果您使用的是 MariaDB 而不是 MySQL,請使用以下命令:
cp $(brew --prefix mariadb)/support-files/my-small.cnf /usr/local/etc/my.cnf
一種查找方法:
sudo /usr/libexec/locate.updatedb
# wait a few minutes for it to finish
locate my.cnf
在我的系統中是
nano /usr/local/etc/my.cnf.default
作為模板和
nano /usr/local/etc/my.cnf
作為工作。
沒有什么真正幫助我 - 我無法覆蓋 /etc/my.cnf 文件中的設置。 所以我像約翰建議的那樣搜索https://stackoverflow.com/a/7974114/717251
sudo /usr/libexec/locate.updatedb
# wait a few minutes for it to finish
locate my.cnf
它發現另一個 my.cnf 在
/usr/local/Cellar/mysql/5.6.21/my.cnf
更改此文件對我有用! 不要忘記重新啟動啟動代理:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
更新:
如果您最近安裝了 homebrew,您應該使用 brew services 命令重新啟動 mysql(使用您安裝的 homebrew mysql 版本,即 mysql 或 mysql@5.7):
brew services stop mysql
brew services start mysql
由於mysql --help
顯示文件列表,我發現將結果通過管道傳輸到ls
以查看其中存在哪些文件很有用:
$ mysql --help | grep /my.cnf | xargs ls
ls: /etc/my.cnf: No such file or directory
ls: /etc/mysql/my.cnf: No such file or directory
ls: ~/.my.cnf: No such file or directory
/usr/local/etc/my.cnf
對於我的(安裝 Homebrew)MySQL 5.7,文件似乎在/usr/local/etc/my.cnf
上。
在你的外殼上輸入my_print_defaults --help
在結果的底部,您應該能夠看到服務器從中讀取配置的文件。 它打印如下內容:
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf
添加另一個答案原因
mysql
,而不是手動安裝的 MySQL 。 my.cnf
在安裝過程中由 Homebrew 復制到以下位置
/usr/local/etc/my.cnf
用於 x86 Mac/opt/homebrew/etc/my.cnf
適用於 M1 Mac Homebrew 選擇/usr/local
或/opt/homebrew
來存儲包,因此默認的 conf 文件不會存儲在/etc/
中,而是/usr/local/etc
或/opt/homebrew/etc
中。
事實上,自制軟件在從源代碼編譯mysql
期間更改了-DSYSCONFDIR=
(默認配置位置)標志。
一個簡短的回答:運行brew info mysql
並檢查提示。
推薦的方式是brew services start mysql
,它使用launchd
來管理服務。 (在 macOS 上, launchd
被認為是systemd
的替代品)
對於任何想要手動啟動它的人來說,沒有任何選項的mysql.start
足以啟動該服務。 ( mysql.start
是mysql
提供的幫助啟動服務的腳本)
服務器版本:8.0.19 Homebrew。 macOS Catalina 10.15.5 並通過 Homebrew 安裝 MySQL。 在這里找到這個文件:
/usr/local/etc/my.cnf
這個解決方案有幫助:)
您可以找到特定軟件包提供my.cnf
文件的位置,例如
brew list mysql # or: mariadb
除了驗證是否讀取了該文件之外,您還可以運行:
sudo fs_usage | grep my.cnf
它將實時顯示與該文件相關的文件系統活動。
我相信答案是否定的。 在 ~/.my.cnf 或 /usr/local/etc 中安裝一個似乎是首選解決方案。
如果是 Homebrew,mysql 也會在它的 Cellar 目錄中查找 my.cnf,例如:
/usr/local/Cellar/mysql/5.7.21/my.cnf
對於這種情況,人們更喜歡將配置保持在二進制文件附近 - 如果my.cnf
丟失,請在此處創建。
修改后重啟mysql:
brew services restart mysql
跑
sudo find / -name my.cnf
通常第一個結果是正確的。 應該在
/usr/local/etc/
如果您使用的是 mac m1 (Apple Silicon),my.cnf 位於
/opt/homebrew/etc/my.cnf
也可以通過mysql --help
找到
我已經使用 Homebrew 安裝了 MySQL 5.7
my.cnf 文件位於“/opt/homebrew/etc/my.cnf”
對於 MacOS (High Sierra),使用 home brew 安裝的 MySQL。
從 mysql 環境中增加全局變量不成功。 所以在這種情況下,創建 ~/.my.cnf 是最安全的選擇。 使用 [mysqld] 添加變量將包括更改(注意:如果使用 [mysql] 更改,更改可能不起作用)。
<~/.my.cnf> [mysqld] connect_timeout = 43200 max_allowed_packet = 2048M net_buffer_length = 512M
重啟mysql服務器。 並檢查變量。 是的
sql> 選擇@@max_allowed_packet; +------------------------+ | @@max_allowed_packet | +------------------------+ | 1073741824 | +------------------------+
一組中的 1 行(0.00 秒)
$ps aux | grep mysqld /usr/local/opt/mysql/bin/mysqld --basedir=/usr/local/opt/mysql --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/opt/mysql/lib/plugin
將 my.cf 文件放到/usr/local/opt/mysql
brew services restart mysql
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.