对于自制的 mysql 安装,my.cnf 在哪里?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7973927/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:30:27  来源:igfitidea点击:

For homebrew mysql installs, where's my.cnf?

mysqlhomebrew

提问by chrismealy

For homebrew mysql installs, where's my.cnf? Does it install one?

对于自制的 mysql 安装,my.cnf 在哪里?它安装一个吗?

采纳答案by Jericon

There is no my.cnf by default. As such, MySQL starts with all of the default settings. If you want to create your own my.cnf to override any defaults, place it at /etc/my.cnf.

默认没有 my.cnf。因此,MySQL 以所有默认设置开始。如果您想创建自己的 my.cnf 以覆盖任何默认值,请将其放在 /etc/my.cnf 中。

Also, you can run mysql --helpand look through it for the conf locations listed.

此外,您可以运行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.

As you can see, there are also some options for bypassing the conf files, or specifying other files to read when you invoke mysql on the command line.

如您所见,还有一些选项可以绕过 conf 文件,或者在命令行上调用 mysql 时指定要读取的其他文件。

回答by ewalshe

The homebrew mysql contains sample configuration files in the installation's support-files folder.

自制软件 mysql 在安装的 support-files 文件夹中包含示例配置文件。

ls $(brew --prefix mysql)/support-files/my-*

If you need to change the default settings you can use one of these as a starting point.

如果您需要更改默认设置,您可以使用其中之一作为起点。

cp $(brew --prefix mysql)/support-files/my-default.cnf /usr/local/etc/my.cnf

As @rednaw points out, a homebrew install of MySQL will most likely be in /usr/localso the my.cnf file should not be added to the system /etcfolder, so I've changed the command to copy the file into /usr/local/etc.

正如@rednaw 指出的那样,MySQL 的自制安装很可能会在其中,/usr/local因此不应将 my.cnf 文件添加到系统/etc文件夹中,因此我更改了将文件复制到/usr/local/etc.

If you are using MariaDB rather than MySQL use the following:

如果您使用的是 MariaDB 而不是 MySQL,请使用以下内容:

cp $(brew --prefix mariadb)/support-files/my-small.cnf /usr/local/etc/my.cnf

回答by John Bachir

One way to find out:

一种查找方法:

sudo /usr/libexec/locate.updatedb
# wait a few minutes for it to finish
locate my.cnf

回答by naabster

Nothing really helped me - I could not overwrite settings in a /etc/my.cnf file. So I searched like John suggested https://stackoverflow.com/a/7974114/717251

没有什么能真正帮助我 - 我无法覆盖 /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

It found another my.cnf in

它在另一个 my.cnf 中找到了

/usr/local/Cellar/mysql/5.6.21/my.cnf

changing this file worked for me! Don't forget to restart the launch Agent:

更改此文件对我有用!不要忘记重新启动启动代理:

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist


Update:

更新:

If you have a fairly recent installation of homebrew you should use the brew services commands to restart mysql (use your installed homebrew mysql version, i.e. mysql or [email protected]):

如果您最近安装了 homebrew,则应使用 brew services 命令重新启动 mysql(使用您安装的 homebrew mysql 版本,即 mysql 或 [email protected]):

brew services stop mysql
brew services start mysql

回答by Fusca Software

in my system it was

在我的系统中是

nano /usr/local/etc/my.cnf.default 

as template and

作为模板和

nano /usr/local/etc/my.cnf

as working.

作为工作。

回答by Emil Stenstr?m

Since mysql --helpshows a list of files, I find it useful to pipe the result to lsto see which of them exist:

由于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

For my (Homebrew installed) MySQL 5.7, it seems the files is on /usr/local/etc/my.cnf.

对于我的(安装 Homebrew)MySQL 5.7,文件似乎位于/usr/local/etc/my.cnf.

回答by Luis Lasser

On your shell type my_print_defaults --help

在你的外壳类型上 my_print_defaults --help

At the bottom of the result, you should be able to see the file from which the server reads the configurations. It prints something like this:

在结果的底部,您应该能够看到服务器从中读取配置的文件。它打印出这样的东西:

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

回答by chrismealy

I believe the answer is no. Installing one in ~/.my.cnf or /usr/local/etc seems to be the preferred solution.

我相信答案是否定的。在 ~/.my.cnf 或 /usr/local/etc 中安装一个似乎是首选的解决方案。

回答by kenorb

You can find where the my.cnffile has been provided by the specific package, e.g.

您可以找到my.cnf特定包提供的文件的位置,例如

brew list mysql # or: mariadb

In addition to verify if that file is read, you can run:

除了验证该文件是否被读取外,您还可以运行:

sudo fs_usage | grep my.cnf

which will show you filesystem activity in real-time related to that file.

这将实时显示与该文件相关的文件系统活动。

回答by Andrey

In case of Homebrew, mysql would also look for my.cnf in it's Cellar directory, for example:

如果是 Homebrew,mysql 还会在它的 Cellar 目录中查找 my.cnf,例如:

/usr/local/Cellar/mysql/5.7.21/my.cnf

For the case one prefers to keep the config close to the binaries - create my.cnfhere if it's missing.

对于更喜欢将配置保持在二进制文件附近的情况 -my.cnf如果缺少,请在此处创建。

Restart mysql after change:

更改后重启mysql:

brew services restart mysql