Find out where my.cnf is located

To find out where the MySQL configuration (my.cnf) is stored, you can use the strace command:

$> strace mysql ";" 2>&1 | grep my.cnf

You will get an output showing all the paths the MySQL deamon searches for the my.cnf upon startup like that:

stat("/etc/my.cnf", 0x7fffecb75210)     = -1 ENOENT (No such file or directory)
stat("/etc/mysql/my.cnf", {st_mode=S_IFREG|0644, st_size=3505, ...}) = 0
open("/etc/mysql/my.cnf", O_RDONLY)     = 3
stat("/usr/etc/my.cnf", 0x7fffecb75210) = -1 ENOENT (No such file or directory)
stat("/home/sheldon/.my.cnf", 0x7fffecb75210) = -1 ENOENT (No such file or directory)

As you can see, the service searches the following files:

  • /etc/my.cnf
  • /etc/mysql/my.cnf
  • /usr/etc/my.cnf
  • /home/sheldon/.my.cnf

But only the /etc/mysql/my.cnf is found and was used. That’s the my.cnf you where looking for.

Leave a Reply

Your email address will not be published.

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.