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

2019-01-09 21:49发布

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

11条回答
姐就是有狂的资本
2楼-- · 2019-01-09 22:11

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

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/local so the my.cnf file should not be added to the system /etc folder, so I’ve changed the command to copy the file into /usr/local/etc.

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

cp $(brew --prefix mariadb)/support-files/my-small.cnf /usr/local/etc/my.cnf
查看更多
beautiful°
3楼-- · 2019-01-09 22:15

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.

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

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.

查看更多
Melony?
4楼-- · 2019-01-09 22:15

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

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

It found another my.cnf in

/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
查看更多
淡お忘
5楼-- · 2019-01-09 22:15

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

$ 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.

查看更多
看我几分像从前
6楼-- · 2019-01-09 22:16

One way to find out:

sudo /usr/libexec/locate.updatedb
# wait a few minutes for it to finish
locate my.cnf
查看更多
手持菜刀,她持情操
7楼-- · 2019-01-09 22:17

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

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

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

Restart mysql after change:

brew services restart mysql
查看更多
登录 后发表回答