Configuring MariaDB Connector/C with Option Files
Contents
Just like MariaDB Server and libmysqlclient, MariaDB Connector/C can also read configuration options from client option groups in option files.
MariaDB Connector/C will only read options from an option file if the application sets the MYSQL_READ_DEFAULT_FILE
option with the mysql_optionsv
function. The application can tell MariaDB Connector/C to use an option file with a specific name by providing the file name as an argument to this function. If it provides a NULL
pointer as the file name, then MariaDB Connector/C will use the standard my.cnf
file name on Unix-like operating systems and either the my.ini
or the my.cnf
file names on Windows.
Option File Locations
MariaDB Connector/C reads option files from many different directories. See the sections below to find out which directories are checked for which system.
Option File Locations on Linux, Unix, Mac
On Linux, Unix, or Mac OS X, the default option file is called my.cnf
. MariaDB Connector/C looks for the MariaDB option file in the locations and orders listed below.
The locations are dependent on whether the DEFAULT_SYSCONFDIR
cmake
option was defined when MariaDB Connector/C 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 Connector/C looks for the MariaDB option file in the following locations in the following order:
Location |
---|
/etc/my.cnf |
/etc/mysql/my.cnf |
$MYSQL_HOME/my.cnf |
~/.my.cnf |
When the DEFAULT_SYSCONFDIR
cmake
option was defined, MariaDB Connector/C looks for the MariaDB option file in the following locations in the following order:
Location |
---|
SYSCONFDIR/my.cnf |
$MYSQL_HOME/my.cnf |
~/.my.cnf |
Option File Locations on Windows
On Windows, the default option file can be called either my.ini
or my.cnf
. MariaDB Connector/C looks for the MariaDB option file in the following locations in the following order:
Location |
---|
Windows System Directory |
Windows Directory (WINDIR) |
C:\ |
INSTALLDIR |
%MYSQL_HOME% |
- The
Windows System Directory
is the directory returned by theGetSystemDirectory
function. The value is usuallyC:\Windows\System32
. - The
Windows Directory
is the directory returned by theGetWindowsDirectory
function. The value is usuallyC:\Windows
. To find its specific value on your system, opencmd.exe
and execute:echo %WINDIR%
- INSTALLDIR is a directory, one level up from
libmariadb.dll
, for example,C:\Program Files\MariaDB Connector/C 3.1
. MYSQL_HOME
is the environment variable containing the path to the directory holding the server-specificmy.cnf
file.
Option File Hierarchy
MariaDB Connector/C will look in all of the above locations, in order, even if has already found a MariaDB option file, and it's possible for more than one MariaDB option file to exist. For example, you could have a MariaDB option file in /etc/mysql/my.cnf
with global settings for all servers, and then you could another MariaDB 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.
Including Additional 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:
[client-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:
[client-mariadb] ... !includedir /etc/my.cnf.d/
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
.
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.
Option File Syntax
The syntax of the MariaDB option 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.
By convention, server variables have usually been specified with an underscore in the option files, and a dash on the command line. You can however specify underscores as dashes - they are interchangeable.
Option Groups
MariaDB Connector/C reads client options from the following option groups in option files:
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. |
The application can tell MariaDB Connector/C to read options from an option group with a specific name by setting the MYSQL_READ_DEFAULT_GROUP
option with the mysql_optionsv
function and providing the name of the option group as an argument to this function.
Supported Options
port
- Description: Port number to use for connection.
- mysql_optionsv: N/A
- Data Type:
int
- Default Value: 3306
socket
- Description: For connections to localhost, the Unix socket file to use, or, on Windows, the name of the named pipe to use.
- mysql_optionsv: N/A
- Data Type:
string
- Default Value:
compress
- Description: Compress all information sent between the client and the server if both support compression.
- mysql_optionsv:
MYSQL_OPT_COMPRESS
- Data Type:
boolean
- Default Value:
false