Location of MySQL's my.cnf filePosted in MySql -
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.
This page was originally posted on November 8th 2010 and had at least one update between then and August 11th 2011. It originally showed locations of the my.cnf file on popular Linux distributions.
It was rewritten on September 10th 2014 to show how to work out where MySQL looks for the my.cnf file instead, because the file often doesn't exist on more recent distros unless you, the administrator, create it first.