59

How do I know which configuration file is used by MySQL currently? Is there any command or something to find it out?

bakkal
  • 54,350
  • 12
  • 131
  • 107
Albin Joseph
  • 1,020
  • 3
  • 16
  • 25

7 Answers7

79

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.

automatix
  • 14,018
  • 26
  • 105
  • 230
GoalBased
  • 1,810
  • 1
  • 14
  • 12
  • 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
  • 1
    The 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
  • SHOW VARIABLES LIKE 'datadir'; – Shyam Gupta May 18 '17 at 19:04
6

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:

"How to find MySQL configuration file?"

Sasha
  • 415
  • 6
  • 5
  • 3
    Can 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
6

If you are using terminal just type the following:

locate my.cnf
DanM7
  • 2,203
  • 3
  • 28
  • 46
Aventador
  • 205
  • 2
  • 11
2

You can use the report process status ps command:

ps ax | grep '[m]ysqld'
DanM7
  • 2,203
  • 3
  • 28
  • 46
1

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

bakkal
  • 54,350
  • 12
  • 131
  • 107
0

you can find it by running the following command

mysql --help

it will give you the mysql installed directory and all commands for mysql.

Chandler Bing
  • 293
  • 4
  • 18
-1

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

Shyam Gupta
  • 489
  • 4
  • 8