Location of MySQL’s my.cnf file


MySQL’s main configuration file is my.cnf and it is located in different locations depending on the operating system, distribution and version. This post shows how to find out where MySQL will look for the config file.

Use mysql + grep to find out where MySQL will look
Running this command from the command line / terminal will show where MySQL will look for the my.cnf file on Linux/BSD/OS X systems:

mysql –help | grep “Default options” -A 1
This will output something like this:

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
You can now check for files using the above output at /etc/my.cnf, then /etc/mysql/my.cnf and so on.

If there isn’t one at one of those locations, you can create one and know MySQL will use it.

Often a distro will have defaults compiled into the MySQL Server and Client, and won’t have even an empty my.cnf file, so if you want to have settings that stick when MySQL is restarted, then you’ll need to create the file and put them in there.