Configuring MariaDB with my.cnf
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
Location | Scope |
---|---|
/etc/my.cnf | Global |
/etc/mysql/my.cnf | Global |
SYSCONFDIR/my.cnf | Global |
$MYSQL_HOME/my.cnf | Server |
defaults-extra-file | File specified with --defaults-extra-file=path, if any |
~/.my.cnf | User |
MariaDB starting with 10.0.13
When SYSCONFDIR
is not defined (for example, in binary tarballs and DEB packages)
Location | Scope |
---|---|
/etc/my.cnf | Global |
/etc/mysql/my.cnf | Global |
$MYSQL_HOME/my.cnf | Server |
defaults-extra-file | File specified with --defaults-extra-file=path, if any |
~/.my.cnf | User |
When SYSCONFDIR
is defined (for example, in RPM packages it is /etc
)
Location | Scope |
---|---|
SYSCONFDIR/my.cnf | Global |
$MYSQL_HOME/my.cnf | Server |
defaults-extra-file | File specified with --defaults-extra-file=path, if any |
~/.my.cnf | User |
SYSCONFDIR
is the directory specified with the CMakeDEFAULT_SYSCONFDIR
(orINSTALL_SYSCONFDIR
if the former is not defined) option when MariaDB was built, by defaultetc
under the compiled-in installation directory.MYSQL_HOME
is the environment variable containing the path to the directory holding the server-specificmy.cnf
file. IfMYSQL_HOME
is not set, and the server is started withmysqld_safe
,MYSQL_HOME
is set as follows:- 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. - Else,
MYSQL_HOME
is set to the MariaDB base directory.
- If there is a
Location in Windows
On Windows, my.ini
can be used as well as my.cnf
, and MariaDB looks in the following locations.
Location | Scope |
---|---|
%PROGRAMDATA%\MySQL\MySQL Server x.x\my.cnf | Global (x.x refers to the version) |
%WINDIR%\my.cnf | Global |
C:\my.cnf | Global |
INSTALLDIR\my.cnf | Global |
defaults-extra-file | File 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 toC:\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, usuallyProgram 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.