Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Location of my.cnf file on macOS

People also ask

Where is the CNF file located?

cnf. It is most often located in the /​etc/​ directory. The file is saved in a plain text format.

Where is my CNF on Mac Mamp?

cnf file located? The configuration file “my. cnf” of MySQL can be found here: “/Applications/MAMP/tmp/mysql/my.

Where is MySQL installed on Mac?

By default, the MySQL directories are installed under /usr/local/ . Even better, add /usr/local/mysql/bin to your PATH environment variable. You can do this by modifying the appropriate startup file for your shell. For more information, see Invoking MySQL Programs.


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

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


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.


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

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.


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

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


I'm running MacOS Catalina(10.15.3) and find my.cnf in /usr/local/etc.