The my.cnf file allows you to configure MariaDB to run the way you want it. Most of the server system variables can be set in the my.cnf file, although usually only a few are, and the rest simply take their default values.

Depending on how you've installed MariaDB, the my.cnf may be in a number of places, or it may not exist at all.

Location in Linux, Unix, Mac

On a Linux, Unix or Mac server, MariaDB looks for the my.cnf file in the following locations:

MariaDB until 10.0.12
defaults-extra-fileFile specified with --defaults-extra-file=path, if any
MariaDB starting with 10.0.13

When SYSCONFDIR is not defined (for example, in binary tarballs and DEB packages)

defaults-extra-fileFile specified with --defaults-extra-file=path, if any

When SYSCONFDIR is defined (for example, in RPM packages it is /etc)

defaults-extra-fileFile specified with --defaults-extra-file=path, if any
  • SYSCONFDIR is the directory specified with the CMake DEFAULT_SYSCONFDIR (or INSTALL_SYSCONFDIR if the former is not defined) option when MariaDB was built, by default etc under the compiled-in installation directory.
  • MYSQL_HOME is the environment variable containing the path to the directory holding the server-specific my.cnf file. If MYSQL_HOME is not set, and the server is started with mysqld_safe, MYSQL_HOME is set as follows:
    1. If there is a my.cnf file in the MariaDB data directory, but not in the MariaDB base directory, MYSQL_HOME is set to the MariaDB data directory.
    2. Else, MYSQL_HOME is set to the MariaDB base directory.

Location in Windows

On Windows, my.ini can be used as well as my.cnf, and MariaDB looks in the following locations.

%PROGRAMDATA%\MySQL\MySQL Server x.x\my.cnfGlobal (x.x refers to the version)
defaults-extra-fileFile specified with --defaults-extra-file=path, if any
  • %PROGRAMDATA% is the file system directory containing application data for all the host's users. It defaults to C:\ProgramData on modern versions of Windows, or to C:\Documents and Settings\All Users\Application Data on Windows XP and before.
  • %WINDIR% is the Windows directory, usually C:\WINDOWS. To find its specific value on your system, use:
    C:\> echo %WINDIR%
  • INSTALLDIR is the MariaDB installation directory from using the Windows installer, usually C:\PROGRAMDIR\MySQL\MySQL 5.5 Server, where PROGRAMDIR in turn is the programs directory, usually Program Files

my.cnf hierarchy

MariaDB will look in all of the above locations, in order, even if has already found a my.cnf file, and it's possible for more than one my.cnf file to exist. For example, you can have a my.cnf file in /etc/mysql/my.cnf with global settings for all servers, and then another my.cnf file in the user's home directory, ~/my.cnf, which will add further (or overwrite) settings specific only to that user.

If no my.cnf file is found, the default values are used for all variables. See server system variables for a full list of all server variables and their default values.

You will most likely also find a sample my.cnf file called my-default.cnf, or, on older releases,,,, and You can choose one of these appropriate for your type of installation, and copy and use as the basis for your my.cnf file.

Configuration syntax and groups

The syntax of the MariaDB and MySQL configuration files are:

  • Lines starting with # are comments.
  • Empty lines are ignored.
  • A group starts with the syntax [group-name]
  • You may have many instances of the same group.
  • !include filename can be used to include other configuration files.
  • !includedir directory can be used to include all configuration files in a given directory. Note that the files are read in alphabetical order.
  • Options prefixed by loose will not produce an error if they don't exist.

A MariaDB / MySQL program can read one or many groups. You can see for each program which configuration files and groups it reads by executing program-name --help --verbose

sh> mysqld --help --verbose

./mysqld  Ver 10.2.1-MariaDB-valgrind-max-debug for Linux on x86_64 (Source distribution)
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Starts the MariaDB database server.

Usage: ./mysqld [OPTIONS]

Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf 
The following groups are read: mysqld server mysqld-10.2 mariadb mariadb-10.2 client-server galera

The configuration files are scanned once, in the order given by --help --verbose. The effect of the configuration options are as if they would have been given as command line options in the order they are found.

You can check which command line optiond a given program is going to use by starting it with the option --print-defaults or using the my_print_defaults program.

sh> ./client/mysqldump --print-defaults
./client/mysqldump would have been started with the following arguments:
--socket=/tmp/mysql-dbug.sock --port=3307 --quick --max_allowed_packet=16M 

sh> my_print_defaults mysqldump

All MariaDB programs read, in addition to the common groups, the group with the same name as the program. For example mysqldump reads the group [mysqldump].

The following general groups are recognized:

client Options read by all clients, like mysqldump
client-serverOptions read by all MariaDB clients and the MariaDB server. This option is MariaDB specific. This is useful for options like socket and port, which is common between the server and the clients
mysqld Read by the mysqld server, both by MariaDB and MySQL
mariadbRead by the MariaDB mysqld server
mysqld-version Read by a specific main version of the mysqld server, both by MariaDB and MySQL. For example mysqld-5.5
mariadb-version Read by a specific main version of the MariaDB mysqld server. For example mariadb-10.1
programname Read by the program programname. Could be for example mysqldump.

By using the mysqld-version syntax, one can create configuration files that will work for both MariaDB and MySQL!

Example of configuration file

The following is an extract of a configuration that one can use if one wants to work with both MySQL and MariaDB.

# Example mysql config file.


# This will be passed to all mysql clients

# Here are entries for some specific programs
# The following values assume you have at least 32M ram

# The MySQL server






You can find some example configuration files, like my-large.cnf, in the support-files or /usr/share/mysql/mysql directory, depending on your installation.


Comments loading...