Answers:
默认情况下没有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时要读取的其他文件。
ls $(brew --prefix mysql)/*.cnf
                    mysql --help | grep cnf实际上更容易找到线条。
                    自制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可能是在本地安装的MySQL,/usr/local因此my.cnf文件不应添加到系统/etc文件夹中,因此我更改了将文件复制到的命令。/usr/local/etc。
如果您使用的是MariaDB而不是MySQL,请使用以下命令:
cp $(brew --prefix mariadb)/support-files/my-small.cnf /usr/local/etc/my.cnfsudo cp $(brew --prefix mysql)/support-files/my-default.cnf /etc/my.cnf
                    /usr/local/其中安装了MySQL (我认为这是默认设置),那么您也可以将my.confin 放置在/usr/local/etc/不需要root特权的位置。
                    brew --prefix mariadb。在MariaDB发行版my-default.cnf中不存在-请使用my-small.cnf。试试这个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.cnfmdfind -name my.cnf而不是locate命令
                    locate my.cnf直接工作。我没有参加sudo /usr/libexec/locate.updatedb
                    /usr/local/Cellar/mysql/8.0.16/.bottle/etc/my.cnf和/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 mysqlbrew services stop mysql,并brew services start mysql在地方的launchctl unload ...线路。
                    由于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.cnf或/ usr / local / etc中安装一个似乎是首选的解决方案。
对于MacOS(High Sierra),已与家庭Brew一起安装的MySQL。
从mysql环境增加全局变量不成功。因此,在这种情况下,创建〜/ .my.cnf是最安全的选择。使用[mysqld]添加变量将包括更改(注意:如果使用[mysql]进行更改,则更改可能无法正常工作)。
<〜/ .my.cnf> [mysqld] connect_timeout = 43200 max_allowed_packet = 2048M net_buffer_length = 512M
重新启动mysql服务器。并检查变量。ÿ
sql> SELECT @@ max_allowed_packet; + ---------------------- + | @@ max_allowed_packet | + ---------------------- + | 1073741824 | + ---------------------- +
设置1行(0.00秒)