Location of my.cnf file on macOS

401,140

Solution 1

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

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

  1. Opening a connection
  2. Selecting the 'Options File' under 'INSTANCE' in the menu.
  3. MySQLWorkbench will search for my.cnf and if it can't find it, it'll create it for you

Solution 2

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

Solution 3

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 - Global
  • /etc/mysql/my.cnf - Global
  • SYSCONFDIR/my.cnf - Global

    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.

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

    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.

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

  • ~/.my.cnf - User-specific
  • ~/.mylogin.cnf - User-specific (clients only)

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.

  1. Run: sudo fs_usage | grep my.cnf

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

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

    brew services restart mysql
    

    or:

    brew services restart mariadb
    
  3. On terminal with fs_usage, the proper location should be shown, e.g.

    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.

Solution 4

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:

  1. /etc/my.cnf
  2. /etc/mysql/my.cnf
  3. SYSCONFDIR/my.cnf
  4. $MYSQL_HOME/my.cnf
  5. defaults-extra-file (the file specified with --defaults-extra-file=path, if any)
  6. ~/.my.cnf

Solution 5

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

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

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

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

Then restart MySQL.

Share:
401,140

Related videos on Youtube

nicolas
Author by

nicolas

Updated on July 08, 2022

Comments

  • nicolas
    nicolas almost 2 years

    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.

    • Artefact2
      Artefact2 almost 12 years
      I think this belongs to serverfault.com. But still, welcome to SO!
  • nicolas
    nicolas almost 12 years
    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
    nicolas almost 12 years
    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!
  • Jpsy
    Jpsy about 10 years
    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
  • m02ph3u5
    m02ph3u5 almost 10 years
    which is /usr/local/Cellar/yourMySqlVersion/my.cnf
  • arcseldon
    arcseldon over 9 years
    also, you do need to have a populated locate db. on mac osx: sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
  • Steven Lizarazo
    Steven Lizarazo over 9 years
    /usr/local/opt/mariadb/VERSIONNUMBER/ in my case MariaDB is installed
  • Darragh Enright
    Darragh Enright over 8 years
    Thanks @Jpsy - that was super helpful.
  • Steve Tauber
    Steve Tauber over 8 years
    Mine is in /usr/local/etc/my.cnf
  • ryantuck
    ryantuck over 8 years
    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
  • trojan
    trojan about 8 years
    Just to be clear, you have to create "etc/" folder yourself and you need root privileges for that "sudo su -"
  • Mirza Vu
    Mirza Vu over 7 years
    Not found in that location for me . I am using MAMP
  • Mirza Vu
    Mirza Vu over 7 years
    create /Applications/MAMP/Library/my.cnf for OSX El Capitan
  • Sergio Rodrigues
    Sergio Rodrigues over 7 years
    @mirzavu, see this link: stackoverflow.com/questions/678645/…
  • Christia
    Christia about 7 years
    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.
  • norman_h
    norman_h about 7 years
    I just installed 5.7.18 on 12.12.4 via homebrew and they are not there.
  • Chris Bartley
    Chris Bartley over 6 years
    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".
  • Pysis
    Pysis over 6 years
    In the same situation as Chris, Mac 10.12.6, native MySQL 5.7.19, I was able to get MySQL Workbench to generate a default configuration file at /etc/my.cnf with a default mysqld section, but I don't think it is taking effect. The file was still empty, so I used that program to show the diff, copied it into a text editor to save with admin permissions, restarted, but still nothing. I wanted to enable named pipes, the socket, and disable the network communication, but doesn't seem to change anything, or it enabled the socket, but did not disable the normal networking connection path.
  • jenny
    jenny over 6 years
    great! you saved my day.
  • gary
    gary over 6 years
    Thanks! the sudo fs_usage | grep my.cnf method is quite efficient. I find this file on folder: /usr/local/etc/my.cnf
  • Andru
    Andru over 6 years
    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!
  • glerYbo
    glerYbo over 6 years
    @Andru If none of them exists, create a new one.
  • Andru
    Andru over 6 years
    @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?
  • glerYbo
    glerYbo over 6 years
    @Andru In any location that is read. If config doesn't exist, MySQL uses the default settings.
  • Alan Snyder
    Alan Snyder over 6 years
    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.
  • undefined
    undefined about 6 years
    Correction: ~/.my.cnf. Add a dot before the file name.
  • Joshua Pinter
    Joshua Pinter almost 6 years
    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.
  • Saurabh Shrivastava
    Saurabh Shrivastava almost 6 years
    Where is "INSTANCE" in the menu? Which menu? My screenshot : imgur.com/a/KyiIwGM
  • Joshua Pinter
    Joshua Pinter almost 6 years
    Mine was /usr/local/mysql/etc. I'm on High Sierra but it was installed a few versions back.
  • Inder
    Inder almost 6 years
    consider adding explanation to your asnwer
  • Ishan Srivastava
    Ishan Srivastava almost 6 years
    you are a life saver
  • Carlos
    Carlos over 5 years
    think different
  • slashdottir
    slashdottir over 5 years
    This answer is old and depends on which installer you used to install mysql. Homebrew puts it one place, the dmg installer puts it another
  • Teddy
    Teddy about 5 years
    As on date, in step 3, the Workbench just says "Location of conf file not specified" and it doesn't generate a new one automatically.
  • wandermonk
    wandermonk almost 5 years
    mysql --help | grep "Default options" -A 1 . this helped.
  • redbirdo
    redbirdo over 4 years
    Your last set of instructions re sudo fs_usage | grep my.cnf was the only thing that helped me on this page, as for some unknown reason mysqld was not loading from the default locations listed via mysql -?
  • Eduard Mukans
    Eduard Mukans over 4 years
    I had the same case, but I also had to add my.cnf file to /etc/my.cnf
  • Shashikant Soni
    Shashikant Soni over 4 years
    That command sudo fs_usage | grep my.cnf saved my day, Thanks a million.
  • aginanjar
    aginanjar over 4 years
    @charles.cc.hsu: try using command locate my.cnf on your terminal. what the result ?
  • civic.LiLister
    civic.LiLister about 4 years
    I checked there, and haven't found it. I finally found that it is in a hidden folder there: .bottle/etc/my.cnf I copied the my.cnf out and modified it. After restart mysql, it worked.
  • B. Bulpett
    B. Bulpett almost 3 years
    Works for me on BigSur with 8.0 installed via homebrew, thanks
  • Paul.j
    Paul.j almost 3 years
    when I execute fs_usage in my Mac terminal, it spilled out 'fs_usage' must be run as root... Do you have any idea what is going on and what to do with it? I did some search and executed this: % sudo fs_usage Password: ktrace_start: Resource busy
  • jbobbins
    jbobbins almost 3 years
    "On Unix platforms, MySQL ignores configuration files that are world-writable" helped solve my issue, thanks! I changed the permissions and it started reading the config file. I would suggest there's a flaw in the mysqld logic that it keeps running by default. If I were mysqld and I saw a config file in the "top-most" location (/etc/my.cnf), and I'm unwilling to read it due to permissions, and I haven't been provided an option that explicitly tells me "sure, just skip right on past config files until you can read one", I would error out and stop running. But I guess I'm not mysqld...yet.