Configuring MariaDB with my.cnf

You are viewing an old version of this article. View the current version here.

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
LocationScope
/etc/my.cnfGlobal
/etc/mysql/my.cnfGlobal
SYSCONFDIR/my.cnfGlobal
$MYSQL_HOME/my.cnfServer
defaults-extra-fileFile specified with --defaults-extra-file=path, if any
~/.my.cnfUser
MariaDB starting with 10.0.13

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

LocationScope
/etc/my.cnfGlobal
/etc/mysql/my.cnfGlobal
$MYSQL_HOME/my.cnfServer
defaults-extra-fileFile specified with --defaults-extra-file=path, if any
~/.my.cnfUser

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

LocationScope
SYSCONFDIR/my.cnfGlobal
$MYSQL_HOME/my.cnfServer
defaults-extra-fileFile specified with --defaults-extra-file=path, if any
~/.my.cnfUser
  • 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.

LocationScope
%PROGRAMDATA%\MySQL\MySQL Server x.x\my.cnfGlobal (x.x refers to the version)
%WINDIR%\my.cnfGlobal
C:\my.cnfGlobal
INSTALLDIR\my.cnfGlobal
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, my-huge.cnf.sh, my-large.cnf.sh, my-medium.cnf.sh, and my-small.cnf.sh. You can choose one of these appropriate for your type of installation, and copy and use as the basis for your my.cnf file.

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.