How to find out the location of currently used MySQL configuration file in linux
MysqlLinuxMysql Problem Overview
How do I know which configuration file is used by MySQL currently? Is there any command or something to find it out?
Mysql Solutions
Solution 1 - Mysql
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.
Solution 2 - Mysql
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:
Solution 3 - Mysql
If you are using terminal just type the following:
locate my.cnf
Solution 4 - Mysql
You can use the report process status ps
command:
ps ax | grep '[m]ysqld'
Solution 5 - Mysql
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
Solution 6 - Mysql
you can find it by running the following command
mysql --help
it will give you the mysql installed directory and all commands for mysql.
Solution 7 - Mysql
login to mysql with proper credential and used mysql>SHOW VARIABLES LIKE 'datadir'; that will give you path of where mysql stored