Location of my.cnf file on macOS
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:
- Opening a connection
- Selecting the 'Options File' under 'INSTANCE' in the menu.
- 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
- GlobalSYSCONFDIR
represents the directory specified with theSYSCONFDIR
option toCMake
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-specificmy.cnf
file resides. IfMYSQL_HOME
is not set and you start the server using themysqld_safe
program,mysqld_safe
sets it toBASEDIR
, 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.
-
Run:
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.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:
/etc/my.cnf
/etc/mysql/my.cnf
SYSCONFDIR/my.cnf
$MYSQL_HOME/my.cnf
-
defaults-extra-file
(the file specified with--defaults-extra-file=path
, if any) ~/.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.