Configuring MariaDB with Option Files

You can configure MariaDB to run the way you want by configuring the server with MariaDB's option files. The default MariaDB option file is called my.cnf on Unix-like operating systems and my.ini on Windows. Depending on how you've installed MariaDB, the default option file may be in a number of places, or it may not exist at all.

The following options relate to how MariaDB handles option files. These options can be used with most of MariaDB's command-line tools, not just mysqld. They must be given as the first argument on the command-line:

OptionDescription
--print-defaultsPrint the program argument list and exit.
--no-defaultsDon't read default options from any option file.
--defaults-file=# Only read default options from the given option file.
--defaults-extra-file=# Read this file after the global files are read.
--defaults-group-suffix=# In addition to the default option groups, also read option groups with this suffix.

Default Option File Locations

MariaDB reads option files from many different directories by default. See the sections below to find out which directories are checked for which system.

For an exact list of option files read on your system by a specific program, you can execute:

$program --help --verbose

For example:

$ mysqld --help --verbose
mysqld  Ver 10.3.13-MariaDB-log for Linux on x86_64 (MariaDB Server)
Copyright (c) 2000, 2018, 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 ~/.my.cnf
The following groups are read: mysqld server mysqld-10.3 mariadb mariadb-10.3 client-server galera
....

The option files are each 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.

Default Option File Locations on Linux, Unix, Mac

On Linux, Unix, or Mac OS X, the default option file is called my.cnf. MariaDB looks for the MariaDB option file in the locations and orders listed below.

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

In MariaDB 10.0.13 and later, the locations are dependent on whether the DEFAULT_SYSCONFDIR cmake option was defined when MariaDB was built. This option is usually defined as /etc when building RPM packages, but it is usually not defined when building DEB packages or binary tarballs.

  • When the DEFAULT_SYSCONFDIR cmake option was not defined, MariaDB looks for the MariaDB option file in the following locations in the following order:
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 the DEFAULT_SYSCONFDIR cmake option was defined, MariaDB looks for the MariaDB option file in the following locations in the following order:
LocationScope
DEFAULT_SYSCONFDIR/my.cnfGlobal
$MYSQL_HOME/my.cnfServer
defaults-extra-fileFile specified with --defaults-extra-file=path, if any
~/.my.cnfUser
  • 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:
    • 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.

Default Option File Locations on Windows

On Windows, the option file can be called either my.ini or my.cnf. MariaDB looks for the MariaDB option file in the following locations in the following order:

LocationScope
Windows System Directory Global
Windows Directory (WINDIR) Global
C:\Global
INSTALLDIR Server
INSTALLDIR\dataServer
%MYSQL_HOME%Global
defaults-extra-fileFile specified with --defaults-extra-file=path, if any
  • The Windows System Directory is the directory returned by the GetSystemDirectory function. The value is usually C:\Windows\System32.
  • The Windows Directory is the directory returned by the GetWindowsDirectory function. The value is usually C:\Windows. To find its specific value on your system, open cmd.exe and execute:
    echo %WINDIR%
  • INSTALLDIR is the parent directory of the directory where mysqld.exe is located. For example, if mysqld.exe is in C:\Program Files\MariaDB 10.3\bin, then INSTALLDIR would be C:\Program Files\MariaDB 10.3.
  • MYSQL_HOME is the environment variable containing the path to the directory holding the server-specific my.cnf file.

Default Option File Hierarchy

MariaDB will look in all of the above locations, in order, even if has already found an option file, and it's possible for more than one option file to exist. For example, you could have an option file in /etc/mysql/my.cnf with global settings for all servers, and then you could another option file in ~/my.cnf, i.e.the user's home directory, which will specify additional settings (or override previously specified setting) that are specific only to that user.

Note that if the --defaults-file option is used, then MariaDB will only read the option file referred to by this option. If the option file referred to by the --defaults-file option does not exist, then MariaDB will raise an error.

If no option file is found, then the default values are used for all options. See Server System Variables for a full list of all server system variables and their default values.

Custom Option File Locations

MariaDB can be configured to read options from custom options files with the following command-line arguments. These command-line arguments can be used with most of MariaDB's command-line tools, not just mysqld. They must be given as the first argument on the command-line:

OptionDescription
--defaults-file=# Only read default options from the given option file.
--defaults-extra-file=# Read this file after the global files are read.

Option File Syntax

The syntax of the MariaDB option files are:

  • Lines starting with # are comments.
  • Empty lines are ignored.
  • Option groups use the syntax [group-name]. See the Option Groups section below for more information on available option groups.
  • The same option group can appear multiple times.
  • The !include directive can be used to include other option files. See the Including Option Files section below for more information on this syntax.
  • The !includedir directive can be used to include all .cnf files (and potentially .ini files) in a given directory. The option files within the directory are read in alphabetical order. See the Including Option File Directories section below for more information on this syntax.
  • Dashes (-) and underscores (_) in options are interchangeable.
  • Options prefixed by loose will not produce an error if they don't exist.
  • See the Options section below for information about available options.

Option Groups

A MariaDB program can read options from one or many option groups. For an exact list of option groups read on your system by a specific program, you can execute:

$program --help --verbose

For example:

$ mysqld --help --verbose
mysqld  Ver 10.3.13-MariaDB-log for Linux on x86_64 (MariaDB Server)
Copyright (c) 2000, 2018, 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 ~/.my.cnf
The following groups are read: mysqld server mysqld-10.3 mariadb mariadb-10.3 client-server galera
....

Server Option Groups

MariaDB programs reads server options from the following server option groups:

GroupDescription
[client-server]Options read by all MariaDB client programs and the MariaDB Server. This is useful for options like socket and port, which is common between the server and the clients.
[server]Options read by MariaDB Server.
[mysqld] Options read by mysqld, which includes both MariaDB Server and MySQL Server.
[mariadb]Options read by MariaDB Server.
[mysqld-X.Y] Options read by a specific version of mysqld, which includes both MariaDB Server and MySQL Server. For example, [mysqld-5.5]
[mariadb-X.Y] Options read by a specific version of MariaDB Server. For example, [mariadb-10.3]
[galera] Options read by a galera-capable MariaDB Server. Available in MariaDB 10.1 and above as well as MariaDB Galera Cluster 5.5 and MariaDB Galera Cluster 10.0.

X.Y in the examples above refer to the base (major.minor) version of the server. For example, MariaDB 10.3.10 would read from [mariadb-10.3]. By using the mariadb-X.Y syntax, one can create option files that have MariaDB-only options in the MariaDB-specific option groups. That would allow the option file to work for both MariaDB and MySQL.

Client Option Groups

MariaDB programs reads client options from the following option groups:

GroupDescription
[client] Options read by all MariaDB and MySQL client programs, which includes both MariaDB and MySQL clients. For example, mysqldump.
[client-server]Options read by all MariaDB client programs and the MariaDB Server. This is useful for options like socket and port, which is common between the server and the clients.
[client-mariadb]Options read by all MariaDB client programs.

In addition to the common groups, many client programs will also read client options from the option group with the same name as the program. For example, mysqldump also reads client options from the [mysqldump] option group.

Custom Option Group Suffixes

MariaDB can be configured to read options from option groups with a custom suffix by providing the following command-line argument. This command-line argument can be used with most of MariaDB's command-line tools, not just mysqld. It must be given as the first argument on the command-line:

OptionDescription
--defaults-group-suffix=# In addition to the default option groups, also read option groups with this suffix.

Including Option Files

It is possible to include additional option files from another option file. For example, to include /etc/mysql/dbserver1.cnf, an option file could contain:

[mariadb]
...
!include /etc/mysql/dbserver1.cnf

Including Option File Directories

It is also possible to include all option files in a directory from another option file. For example, to include all option files in /etc/my.cnf.d/, an option file could contain:

[mariadb]
...
!includedir /etc/my.cnf.d/

The option files within the directory are read in alphabetical order.

All option file names must end in .cnf on Unix-like operating systems. On Windows, all option file names must end in .cnf or .ini.

Checking Program Options

You can check which options a given program is going to use by using the --print-defaults command-line argument:

OptionDescription
--print-defaultsPrint the program argument list and exit.

This command-line argument can be used with most of MariaDB's command-line tools, not just mysqld. It must be given as the first argument on the command-line. For example:

$ mysqldump --print-defaults
mysqldump would have been started with the following arguments:
--ssl_cert=/etc/my.cnf.d/certificates/client-cert.pem --ssl_key=/etc/my.cnf.d/certificates/client-key.pem --ssl_ca=/etc/my.cnf.d/certificates/ca.pem --ssl-verify-server-cert --max_allowed_packet=1GB

You can also check which options a given program is going to use by using the my_print_defaults utility and providing the names of the option groups that the program reads. For example:

$ my_print_defaults mysqldump client client-server client-mariadb
--ssl_cert=/etc/my.cnf.d/certificates/client-cert.pem
--ssl_key=/etc/my.cnf.d/certificates/client-key.pem
--ssl_ca=/etc/my.cnf.d/certificates/ca.pem
--ssl-verify-server-cert
--max_allowed_packet=1GB

The my_print_defaults utility's --mysqld command-line option provides a shortcut to refer to all of the server option groups:

$ my_print_defaults --mysqld
--log_bin=mariadb-bin
--log_slave_updates=ON
--ssl_cert=/etc/my.cnf.d/certificates/server-cert.pem
--ssl_key=/etc/my.cnf.d/certificates/server-key.pem
--ssl_ca=/etc/my.cnf.d/certificates/ca.pem

MySQL 5.6 Obfuscated Authentication Credential Option File

MySQL 5.6 and above support an obfuscated authentication credential option file called .mylogin.cnf that is created with mysql_config_editor.

MariaDB does not support this. The passwords in MySQL's .mylogin.cnf are only obfuscated, rather than encrypted, so the feature does not really add much from a security perspective. It is more likely to give users a false sense of security, rather than to seriously protect them.

Options

Dashes (-) and underscores (_) in options are interchangeable.

Options prefixed by loose will not produce an error if they don't exist.

If an option is not explicitly set, then the server or client will simply use the default value for that option.

MariaDB Server Options

MariaDB Server options can be set in server option groups.

For a list of options that can be set for MariaDB Server, see the list of options available for mysqld.

Most of the server system variables can also be set in MariaDB's option file.

MariaDB Client Options

MariaDB client options can be set in client option groups.

See the specific page for each client program to determine what options are available for that program.

Example Option Files

Most MariaDB installations include a sample MariaDB option file called my-default.cnf. On older releases, you would have also found the following option files:

  • my-small.cnf
  • my-medium.cnf
  • my-large.cnf
  • my-huge.cnf

However, these option files are now very dated for modern servers, so they were removed in MariaDB 10.3.1.

In source distributions, the sample option files are usually found in the support-files directory, and in other distributions, the option files are usually found in the share/mysql directory that is relative to the MariaDB base installation directory.

You can copy one of these sample MariaDB option files and use it as the basis for building your server's primary MariaDB option file.

Example Minimal Option File

The following is a minimal my.cnf file that you can use to test MariaDB.

[client-server]
# Uncomment these if you want to use a nonstandard connection to MariaDB
#socket=/tmp/mysql.sock
#port=3306

# This will be passed to all MariaDB clients
[client]
#password=my_password

# The MariaDB server
[mysqld]
# Directory where you want to put your data
data=/usr/local/mysql/var
# Directory for the errmsg.sys file in the language you want to use
language=/usr/local/share/mysql/english

# This is the prefix name to be used for all log, error and replication files
log-basename=mysqld

# Enable logging by default to help find problems
general-log
log-slow-queries

Example Hybrid Option File

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

# Example mysql config file.

[client-server]
socket=/tmp/mysql-dbug.sock
port=3307

# This will be passed to all mysql clients
[client]
password=my_password

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

# The MySQL server
[mysqld]
temp-pool
key_buffer_size=16M
datadir=/my/mysqldata
loose-innodb_file_per_table

[mariadb]
datadir=/my/data
default-storage-engine=aria
loose-mutex-deadlock-detector
max-connections=20

[mariadb-5.5]
language=/my/maria-5.5/sql/share/english/
socket=/tmp/mysql-dbug.sock
port=3307

[mariadb-10.1]
language=/my/maria-10.1/sql/share/english/
socket=/tmp/mysql2-dbug.sock

[mysqldump]
quick
max_allowed_packet=16M

[mysql]
no-auto-rehash
loose-abort-source-on-error

See Also

Comments

Comments loading...