How to find my.cnf MySQL configuration file in Linux?

After installing MySQL and in order to provide configuration to it, we usually want to locate the famous my.cnf configuration file; if you are running a GNU/Linux distribution like Ubuntu, then you can use the following command to know where is the absolute path of this file:

find / -name my.cnf

The output of this command should be something like this:

/etc/alternatives/my.cnf
/etc/mysql/my.cnf
/var/lib/dpkg/alternatives/my.cnf

The important path here is /etc/mysql/my.cnf and if you open this file with an editor like nano:

nano /etc/mysql/my.cnf

It is normal this file doesn’t have all the configuration, instead if could point to other directories or files, for example this is a configuration file from a fresh Ubuntu install:

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

If you notice there are other directories with configuration files, in particular our extra config is available in:

cat /etc/mysql/mysql.conf.d/mysqld.cnf

In the /etc/mysql/mysql.conf.d/mysqld.cnf file you will find all the parameters used by MySQL, for example port, cache limits, logs paths, SSL, etc.

So, there you go! Continue customizing your MySQL instance.

See you next time.

Alex Arriaga

One comment on “How to find my.cnf MySQL configuration file in Linux?”

Leave a Reply

Your email address will not be published. Required fields are marked *