How do I know which configuration file is used by MySQL currently? Is there any command or something to find it out?
-
2This likely belongs on serverfault.com – George Marian Jul 17 '10 at 05:21
7 Answers
The information you want can be found by running
mysql --help
or
mysqld --help --verbose
I tried this command on my machine:
mysql --help | grep "Default options" -A 1
And it printed out:
Default options are read from the following files in the given order:
/etc/my.cnf /usr/local/etc/my.cnf ~/.my.cnf
See if that works for you.
-
4+1 Another way is 'my_print_defaults mysqld' (to find what options will be passed to mysqld when it's started). – Morgan Tocker Jul 24 '10 at 19:12
-
1The Default options may work on a standard system. I was working on a highly configured system and the default location wasn't available. So I used the answer below to use "locate my.cnf" which provided me the exact location of my file. – Varun Verma Apr 06 '17 at 18:20
-
mysqld --help --verbose will find only location of default configuration file. What if you use 2 MySQL instances on the same server? It's not going to help.
Good article about figuring it out:

- 415
- 6
- 5
-
3Can you Please share new link as now this article is no longer exists :( – Mayank Jain Jul 26 '17 at 06:38
-
New link here of the original article. When I have time I will update this answer with a summary: http://www.psce.com/blog/2012/04/01/how-to-find-mysql-configuration-file/ – Dom Mar 05 '22 at 13:30
If you are using terminal just type the following:
locate my.cnf
-
1I have like 40 of these files using "locate" and I still have no idea which is the right one – Jason FB Nov 17 '15 at 18:17
-
That's fine, presuming it exists - sometimes my.conf doesn't exist. – Dave Everitt May 22 '17 at 12:18
-
You should find them by default in a folder like /etc/my.cnf
, maybe also depends on versions. From MySQL Configuration File:
Interestingly, the scope of this file can be set according to its location. The settings will be considered global to all MySQL servers if stored in /etc/my.cnf. It will be global to a specific server if located in the directory where the MySQL databases are stored (/usr/local/mysql/data for a binary installation, or /usr/local/var for a source installation). Finally, its scope could be limited to a specific user if located in the home directory of the MySQL user (~/.my.cnf). Keep in mind that even if MySQL does locate a my.cnf file in /etc/my.cnf (global to all MySQL servers on that machine), it will continue its search for a server-specific file, and then a user-specific file. You can think of the final configuration settings as being the result of the /etc/my.cnf, mysql-data-dir/my.cnf, and ~/.my.cnf files.
There are a few switches to package managers to list specific files.
RPM Sytems:
There are switches to rpm
command, -q
for query, and -c
or --configfiles
to list config files. There is also -l
or --list
The --configfiles
one didn't quiet work for me, but --list
did list a few .cnf
files held by mysql-server
rpm -q --list mysql-server
DEB Systems:
Also with limited success: dpkg --listfiles mysql-server

- 54,350
- 12
- 131
- 107
you can find it by running the following command
mysql --help
it will give you the mysql installed directory and all commands for mysql.

- 293
- 4
- 18
login to mysql with proper credential and used mysql>SHOW VARIABLES LIKE 'datadir'; that will give you path of where mysql stored

- 489
- 4
- 8
-
This does not answer the question. The default location of the config is never the $datadir. – utdrmac Oct 30 '17 at 20:54