Location of my.cnf file on macOS

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Location of my.cnf file on macOS



I'm trying to follow along this tutorial to enable remote access to MySQL. The problem is, where should my.cnf file be located? I'm using Mac OS X Lion.


my.cnf





I think this belongs to serverfault.com. But still, welcome to SO!
– Artefact2
May 25 '12 at 15:28






21 Answers
21



This thread on the MySQL forum says:



By default, the OS X installation does not use a my.cnf, and MySQL just uses the default values. To set up your own my.cnf, you could just create a file straight in /etc.



OS X provides example configuration files at /usr/local/mysql/support-files/.


/usr/local/mysql/support-files/



And if you can't find them there, MySQLWorkbench can create them for you by:





Thanks!! So just in /usr/etc? Or should I make some kind of mysql directory there? :) edit Found the answer to that on the link, thanks!
– nicolas
May 25 '12 at 15:35







At least the current MySQL package for Mac OS X (mysql-5.6.17-osx10.7-x86_64 at the time of this writing) does in fact create and use a my.cnf. It is located at /usr/local/mysql-5.6.17-osx10.7-x86_64/my.cnf
– Jpsy
May 19 '14 at 11:07





you may want to ensure that mysql is actually loading in whichever my.cnf file you're editing via mysql --verbose --help | grep my.cnf
– Ryan Tuck
Feb 22 '16 at 16:25


my.cnf


mysql --verbose --help | grep my.cnf





On Mac OS Sierra, it wasn't set up already. I had to copy /usr/local/mysql/support-files/my-default.cnf to my.cnf in the same dir. Note that the mysql is symlinked to the package, in my case mysql-5.7.17-macos10.12-x86_64.
– Christia
Mar 23 '17 at 19:20





Just did a clean install of MySQL 5.7.19 on Mac OS 10.12 using the .dmg from dev.mysql.com. There's no my.cnf in any of the places that mysql --help says it looks in. And there's no my-default.cnf in /usr/local/mysql/support-files/ or anywhere else I've found. Turns out that "as of MySQL 5.7.18, my-default.cnf is no longer included in or installed by distribution packages".
– Chris Bartley
Sep 11 '17 at 17:49



In case of Mac OS X Maverick when MySQL is installed via Homebrew it's located at /usr/local/opt/mysql/my.cnf


/usr/local/opt/mysql/my.cnf





which is /usr/local/Cellar/yourMySqlVersion/my.cnf
– m02ph3u5
Jul 29 '14 at 10:24





/usr/local/opt/mariadb/VERSIONNUMBER/ in my case MariaDB is installed
– Steven Lizarazo
Feb 2 '15 at 6:11





same for yosemite
– Ryan Tuck
Aug 5 '15 at 19:09





Mine is in /usr/local/etc/my.cnf
– Steve Tauber
Nov 26 '15 at 18:22





Mine was /usr/local/mysql/etc. I'm on High Sierra but it was installed a few versions back.
– Joshua Pinter
Jul 19 at 23:23


/usr/local/mysql/etc



In general, on Unix and Unix-like systems, MySQL/MariaDB programs read config/startup files in the following locations (in the specified order):


/etc/my.cnf


/etc/mysql/my.cnf



SYSCONFDIR/my.cnf - Global


SYSCONFDIR/my.cnf



SYSCONFDIR represents the directory specified with the SYSCONFDIR option to CMake when MySQL was built. By default, this is the etc directory located under the compiled-in installation directory.


SYSCONFDIR


SYSCONFDIR


CMake



$MYSQL_HOME/my.cnf - Server-specific (server only)


$MYSQL_HOME/my.cnf



MYSQL_HOME is an environment variable containing the path to the directory in which the server-specific my.cnf file resides. If MYSQL_HOME is not set and you start the server using the mysqld_safe program, mysqld_safe sets it to BASEDIR, the MySQL base installation directory.


MYSQL_HOME


my.cnf


MYSQL_HOME


mysqld_safe


mysqld_safe


BASEDIR



file specified with --defaults-extra-file=path if any


--defaults-extra-file=path


~/.my.cnf


~/.mylogin.cnf



Source: Using Option Files.



Note: On Unix platforms, MySQL ignores configuration files that are world-writable. This is intentional as a security measure.



Additionally on Mac there is a simple way to check it.



Run: sudo fs_usage | grep my.cnf


sudo fs_usage | grep my.cnf



This will report any filesystem activity in real-time related to that file.



In another Terminal, restart your MySQL/MariaDB, e.g.


brew services restart mysql



or:


brew services restart mariadb



On terminal with fs_usage, the proper location should be shown, e.g.


fs_usage


15:52:22 access /usr/local/Cellar/mariadb/10.1.14/my.cnf 0.000002 sh



So if the file doesn't exist, create one.





Thanks! the sudo fs_usage | grep my.cnf method is quite efficient. I find this file on folder: /usr/local/etc/my.cnf
– gary
Jan 5 at 8:52


sudo fs_usage | grep my.cnf





Great method, however I get several results there: private/etc/my.cnf, /usr/local/etc/my.cnf, /usr/local/Cellar/mysql/<myVersion>/my.cnf, ~.my.cnfwith my_print_def in the right-most column. Then after a while it's only /usr/local/etc/my.cnf with my terminal in the right-most column. But all of these my.cnf files don't exist!
– Andru
Jan 17 at 13:14




private/etc/my.cnf


/usr/local/etc/my.cnf


/usr/local/Cellar/mysql/<myVersion>/my.cnf


~.my.cnf


my_print_def


/usr/local/etc/my.cnf


my.cnf





@Andru If none of them exists, create a new one.
– kenorb
Jan 17 at 13:25





@kenorb Ok. At any of the listed locations? And what does actually happen there if the my.cnf files don't exist? Is it showing that it searches for my.cnf files there? What would be the order in which they are read? Or is just used? If so, which one?
– Andru
Jan 17 at 13:30


my.cnf


my.cnf





@Andru In any location that is read. If config doesn't exist, MySQL uses the default settings.
– kenorb
Jan 17 at 13:32



I don't know which version of MySQL you're using, but here are possible locations of the my.cnf file for version 5.5 (taken from here) on Mac OS X:


/etc/my.cnf


/etc/mysql/my.cnf


SYSCONFDIR/my.cnf


$MYSQL_HOME/my.cnf


defaults-extra-file


--defaults-extra-file=path


~/.my.cnf



For MySQL 5.7 on Mac OS X El Capitan: /usr/local/mysql/etc/my.cnf


/usr/local/mysql/etc/my.cnf



Copy default conf from /usr/local/mysql/support-files/my-default.cnf


/usr/local/mysql/support-files/my-default.cnf





Just to be clear, you have to create "etc/" folder yourself and you need root privileges for that "sudo su -"
– trojan
May 23 '16 at 8:35





Thank you @trojan
– user3717115
Sep 3 '16 at 4:01





Not found in that location for me . I am using MAMP
– mirza vu
Oct 18 '16 at 17:29





@mirzavu, see this link: stackoverflow.com/questions/678645/…
– Sergio Rodrigues
Oct 19 '16 at 12:03



The current MySQL package for Mac OS X Mavericks (mysql-5.6.17-osx10.7-x86_64 at the time of this writing) automatically creates a my.cnf during installation.



It is located at /usr/local/mysql-5.6.17-osx10.7-x86_64/my.cnf
Adapt your path according to your version.


/usr/local/mysql-5.6.17-osx10.7-x86_64/my.cnf



In mysql 5.6.22, which I installed it from Homebrew, the path of my.cnf is


/usr/local/opt/mysql/my.cnf



You can open a terminal and type locate my.cnf


locate my.cnf





Sorry to not be specific enough, I apparently need to copy 'my-large.cnf' to some folder and rename it 'my.cnf'. But I don't know to where..
– nicolas
May 25 '12 at 15:33





also, you do need to have a populated locate db. on mac osx: sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
– arcseldon
Oct 18 '14 at 10:16



If you are using macOS Sierra and the file doesn't exists,
run



mysql --help or mysql --help | grep my.cnf


mysql --help or mysql --help | grep my.cnf



to see the possible locations and loading/reading sequence of my.cnf for mysql then create my.cnf file in one of the suggested directories then add the following line



[mysqld]
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION


[mysqld]
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION



You can sudo touch /{preferred-path}/my.cnf then edit the file to add sql mode by


sudo touch /{preferred-path}/my.cnf



sudo nano /{preferred-path}/my.cnf


sudo nano /{preferred-path}/my.cnf



Then restart mysql, voilaah you are good to go. happy coding



So none of these things worked for me. I am using the current dmg install of mysql community server. ps shows that all of the most critical parameters normally in my.cnf are passed on the command line, and I couldn't figure out where that was coming from. After doing a full text search of my box I found it in:



/Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist



So you can either change them there, or take them out so it will actually respect the ones you have in your my.cnf wherever you decided to put it.



Enjoy!





great! you saved my day.
– jenny
Dec 1 '17 at 15:23



you can check the file /usr/local/bin/mysql.server and see from where my.conf is being read. usually it is from /etc/my.cnf or ~/my.cnf





Correction: ~/.my.cnf. Add a dot before the file name.
– Shelton
Mar 14 at 4:19


~/.my.cnf



For MAMP 3.5 Mac El Capitan, create a separate empty config file and write your additional settings for mysql


sudo vim /Applications/MAMP/Library/my.cnf



And Add like this


[mysqld]
max_allowed_packet = 256M



I checked in macOS Sierra, the homebrew installed MySql 5.7.12


MySql 5.7.12



The support files are located at


/usr/local/opt/mysql/support-files



Just copy my-default.cnf as /etc/my.cnf or /etc/mysql/my.cnf and the configuration will be picked up on restart.


my-default.cnf


/etc/my.cnf


/etc/mysql/my.cnf





I just installed 5.7.18 on 12.12.4 via homebrew and they are not there.
– norman_h
Apr 29 '17 at 3:48



I am using mysql version 5.7.17 in macOS High Sierra version 10.13.3 and I have found the mysql config file here.


cd /usr/local/mysql/support-files/my-default.cnf





Thanks for the tip on finding the default configuration file. Note, this is just a template file so you'll want to copy this to a location found in mysql --verbose --help | grep my.cnf where it will get picked up, as per: DO NOT EDIT THIS FILE. It's a template which will be copied to the default location during install, and will be replaced if you upgrade to a newer version of MySQL.
– Joshua Pinter
Jun 9 at 22:42




mysql --verbose --help | grep my.cnf


DO NOT EDIT THIS FILE. It's a template which will be copied to the default location during install, and will be replaced if you upgrade to a newer version of MySQL.



For Mac , what worked for me is creating a .my.cnf file in my ~ path. Hope this helps.



Copy /usr/local/opt/mysql/support-files/my-default.cnf as /etc/my.cnf or /etc/mysql/my.cnf and then restart mysql.



For me in sierra version



copy the default configuration at:



/usr/local/Cellar/mysql/5.6.27/support-files/my-default.cnf



to



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



In my case, the file did not exist. In MySQL Workbench I went to OPTIONS FILE and found some default values. I clicked apply. It asked for permission. It then created the my.cnf file under /etc. However, it is very important to keep in mind that the first time you click "apply", you do not make any changes to the default configuration. Once the file has been created, you can make changes which will be applied when you click "apply". Otherwise you will not be shown the apply button when you make changes.





How do i access mysql workbench
– charan teja
Feb 21 at 12:54





I have an options file at /etc/mysql/my.cnf but MySQL Workbench is not aware of it. Instead, it complains that the configuration file with an empty path cannot be found and then offers to create a new file.
– Alan Snyder
Feb 21 at 18:13


/etc/mysql/my.cnf



After the 5.7.18 version of MySQL, it does not provide the default configuration file in support-files directory.
So you can create my.cnf file manually in the location where MySQL will read, like /etc/mysql/my.cnf, and add the configuration you want to add in the file.



rDefault options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf



macOS High Sierra
version 10.13.6



mysql Ver 14.14 Distrib 5.7.22, for osx10.13 (x86_64) using EditLine wrapper
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved



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 clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

etQBaJbnS
IfWZdEj5G,y EErPYjKKl8i,C6i06eXA5K f,o,sx6GW kibUgC 9gIYCLsp1f OWMi9VYQyPwKQUEMrNF

Popular posts from this blog

Makefile test if variable is not empty

Visual Studio Code: How to configure includePath for better IntelliSense results

Will Oldham