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:
Option | Description |
---|---|
--print-defaults |
Read options from option files, print all option values, and then exit the program. |
--no-defaults |
Don't read options from any option file. |
--defaults-file =path
|
Only read options from the given option file. |
--defaults-extra-file =path
|
Read this extra option file after all other option files are read. |
--defaults-group-suffix =suffix
|
In addition to the default option groups, also read option groups with the given suffix. |
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.
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.
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.
DEFAULT_SYSCONFDIR
cmake
option was not defined, MariaDB looks for the MariaDB option file in the following locations in the following order: 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 , if any |
~/.my.cnf |
User |
DEFAULT_SYSCONFDIR
cmake
option was defined, MariaDB looks for the MariaDB option file in the following locations in the following order: Location | Scope |
---|---|
DEFAULT_SYSCONFDIR/my.cnf |
Global |
$MYSQL_HOME/my.cnf |
Server |
defaults-extra-file | File specified with --defaults-extra-file , if any |
~/.my.cnf |
User |
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 , if any |
~/.my.cnf |
User |
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: my.cnf
file in the MariaDB data directory, but not in the MariaDB base directory, MYSQL_HOME
is set to the MariaDB data directory. MYSQL_HOME
is set to the MariaDB base directory. 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:
Location | Scope |
---|---|
System Windows Directory\my.ini |
Global |
System Windows Directory\my.cnf |
Global |
Windows Directory\my.ini |
Global |
Windows Directory\my.cnf |
Global |
C:\my.ini |
Global |
C:\my.cnf |
Global |
INSTALLDIR\my.ini |
Server |
INSTALLDIR\my.cnf |
Server |
INSTALLDIR\data\my.ini |
Server |
INSTALLDIR\data\my.cnf |
Server |
%MYSQL_HOME%\my.ini |
Server |
%MYSQL_HOME%\my.cnf |
Server |
defaults-extra-file | File specified with --defaults-extra-file , if any |
System Windows Directory
is the directory returned by the GetSystemWindowsDirectory
function. The value is usually C:\Windows
. To find its specific value on your system, open cmd.exe
and execute: echo %WINDIR%
Windows Directory
is the directory returned by the GetWindowsDirectory
function. The value may be a private Windows Directory
for the application, or it may be the same as the System Windows Directory
returned by the GetSystemWindowsDirectory
function. 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. 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/my.cnf
with global settings for all servers, and then you could another option file in ~/.my.cnf
(i.e.your user account's home directory) which will specify additional settings (or override previously specified setting) that are specific only to that user.
Option files are usually optional. However, if the --defaults-file
option is set, and if the file does not exist, then MariaDB will raise an error. If the --defaults-file
option is set, then MariaDB will only read the option file referred to by this option.
If an option or system variable is not explicitly set, then it will be set to its default value. See Server System Variables for a full list of all server system variables and their default values.
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:
Option | Description |
---|---|
--defaults-file =path
|
Only read options from the given option file. |
--defaults-extra-file =path
|
Read this extra option file after all other option files are read. |
The syntax of the MariaDB option files are:
[group-name]
. See the Option Groups section below for more information on available option groups. !include
directive can be used to include other option files. See the Including Option Files section below for more information on this syntax. !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. -
) and underscores (_
) in options are interchangeable. 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 ....
MariaDB programs reads server options from the following server option groups:
Group | Description |
---|---|
[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 MariaDB Server, but only if it is compiled with Galera Cluster support. In MariaDB 10.1 and later, all builds on Linux are compiled with Galera Cluster support. When using one of these builds, options from this option group are read even if the Galera Cluster functionality is not enabled. |
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.
MariaDB programs reads client options from the following option groups:
Group | Description |
---|---|
[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.
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:
Option | Description |
---|---|
--defaults-group-suffix =suffix
|
In addition to the default option groups, also read option groups with the given suffix. |
The default group suffix can also be specified via the MYSQL_GROUP_SUFFIX
environment variable.
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
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
.
You can check which options a given program is going to use by using the --print-defaults
command-line argument:
Option | Description |
---|---|
--print-defaults |
Read options from option files, print all option values, and then exit the program. |
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 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.
MariaDB supports certain prefixes that can be used with options. The supported option prefixes are:
Option Prefix | Description |
---|---|
autoset |
Sets the option value automatically. Only supported for certain options. Available in MariaDB 10.1.7 and later. |
disable |
For all boolean options, disables the setting (equivalent to setting it to 0 ). Same as skip . |
enable |
For all boolean options, enables the setting (equivalent to setting it to 1 ). |
loose |
Don't produce an error if the option doesn't exist. |
maximum |
Sets the maximum value for the option. |
skip |
For all boolean options, disables the setting (equivalent to setting it to 0 ). Same as disable . |
For example:
[mariadb] ... # determine a good value for open_files_limit automatically autoset_open_files_limit # disable the unix socket plugin disable_unix_socket # enable the slow query log enable_slow_query_log # don't produce an error if these options don't exist loose_file_key_management_filename = /etc/mysql/encryption/keyfile.enc loose_file_key_management_filekey = FILE:/etc/mysql/encryption/keyfile.key loose_file_key_management_encryption_algorithm = AES_CTR # set max_allowed_packet to maximum value maximum_max_allowed_packet # disable external locking for MyISAM skip_external_locking
Dashes (-
) and underscores (_
) in options are interchangeable.
If an option is not explicitly set, then the server or client will simply use the default value for that option.
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 can be set in client option groups.
See the specific page for each client program to determine what options are available for that program.
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.
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
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
© 2019 MariaDB
Licensed under the Creative Commons Attribution 3.0 Unported License and the GNU Free Documentation License.
https://mariadb.com/kb/en/configuring-mariadb-with-option-files/