How do I find the MySQL my.cnf location

linux, mysql

Solution

There is no internal MySQL command to trace this, it's a little too abstract. The file might be in 5 (or more?) locations, and they would all be valid because they load cascading.

- /etc/my.cnf

- /etc/mysql/my.cnf

- $MYSQL_HOME/my.cnf

- [datadir]/my.cnf

- ~/.my.cnf

Those are the default locations MySQL looks at. If it finds more than one, it will load each of them & values override each other (in the listed order, I think). Also, the `--defaults-file` parameter can override the whole thing, so... basically, it's a huge pain in the butt.

But thanks to it being so confusing, there's a good chance it's just in /etc/my.cnf.

(If you just want to see the values: `SHOW VARIABLES`, but you'll need the permissions to do so.)

Run `mysql --help` and you will see:

`Default options are read from the following files in the given order: /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf`

Problem

Is there a MySQL command to locate the `my.cnf` configuration file, similar to how PHP's `phpinfo()` locates its `php.ini`?

Original source