对于自制mysql安装,my.cnf在哪里?它安装了吗?
当前回答
添加另一个答案
公认的答案是正确的。因为我们讨论的是Homebrew安装的mysql,而不是手动安装的mysql,所以有更直接的方法来查找conf。 前一个答案可能有点过时,Homebrew在M1 Mac上存储在不同的位置
Conf
在安装过程中,my.cnf会被Homebrew复制到以下位置
/usr/local/etc/my.cnf for x86 Mac /opt/homebrew/etc/my.cnf
Homebrew选择/usr/local或/opt/ Homebrew存储包,因此默认的conf文件不存储在/etc/中,而是存储在/usr/local/etc或/opt/ Homebrew /etc中。
事实上,homebrew在从源代码编译mysql时改变了-DSYSCONFDIR=(默认的conf位置)标志。
启动服务
一个简单的回答:运行brew info mysql并查看提示。
推荐使用“brew services start mysql”,使用launchd管理服务。(launchd被认为是macOS上的systemd选项)
如果有人想手动启动,请使用mysql。没有任何选项的启动就足以启动服务。(mysql。Start是mysql提供的帮助启动服务的脚本)
其他回答
有一种方法可以知道:
sudo /usr/libexec/locate.updatedb
# wait a few minutes for it to finish
locate my.cnf
我相信答案是否定的。在~/.my.cnf或/usr/local/etc中安装一个似乎是首选的解决方案。
默认情况下没有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时指定要读取的其他文件。
homebrew 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文件不应该被添加到system /etc文件夹中,所以我改变了命令,将文件复制到/usr/local/etc中
如果你正在使用MariaDB而不是MySQL,请使用以下命令:
cp $(brew --prefix mariadb)/support-files/my-small.cnf /usr/local/etc/my.cnf
在shell上输入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