- Creating a Data Source with MariaDB Connector/ODBC
- Contents
- Creating a Data Source with MariaDB Connector/ODBC on Windows
- Creating a Data Source with MariaDB Connector/ODBC on Linux
- Configuring MariaDB Connector/ODBC as a UnixODBC Driver on Linux
- Configuring a DSN with UnixODBC on Linux
- Verifying a DSN Configuration with UnixODBC on Linux
- Changing UnixODBC’s Configuration File Paths
- Creating a Data Source with MariaDB Connector/ODBC on Mac OS X
- Creating a Data Source with iODBC Administrator on Mac OS X
- Creating a Data Source with iODBC on Mac OS X
- Configuring MariaDB Connector/ODBC as a iODBC Driver on Mac OS X
- Configuring a DSN with iODBC on Mac OS X
- Verifying a DSN Configuration with iODBC on Mac OS X
- About MariaDB Connector/ODBC
- Recent Releases
- Contents
- Installing MariaDB Connector/ODBC
- Installing MariaDB Connector/ODBC on Windows
- Installing MariaDB Connector/ODBC on Linux
- Installing MariaDB Connector/ODBC on RHEL/CentOS
- Installing MariaDB Connector/ODBC on Debian/Ubuntu
- Installing MariaDB Connector/ODBC on Mac OS X
- Installing MariaDB Connector/ODBC from Source
- Installing UnixODBC on Linux
- Creating a Data Source with MariaDB Connector/ODBC
- Installing Client Authentication Plugins
- Parameters
- DSN-Related Parameters
- Logging-Related Parameters
- General Connection Parameters
- General Connection Parameters Example
- TLS-Related Connection Parameters
- TLS-Related Connection Parameters Examples
- Known Issues
- Multiple Statement Execution
- Authenticating with PAM
- Reporting Bugs
- Source Code
- License
Creating a Data Source with MariaDB Connector/ODBC
Contents
MariaDB Connector/ODBC is a database driver that uses the industry standard Open Database Connectivity (ODBC) API. Some of the key features of the driver are:
- It is LGPL-licensed.
- It is compliant with the ODBC 3.5 standard.
- It can be used as a drop-in replacement for MySQL Connector/ODBC.
- It supports both Unicode and ANSI modes.
- It primarily uses the MariaDB/MySQL binary protocol (i.e. server-side prepared statements).
The current release series are:
- MariaDB Connector/ODBC 3.1 is the current stable release series.
- MariaDB Connector/ODBC 2.0 is the previous stable release series, which is currently still supported.
This page discusses how to create a data source with MariaDB Connector/ODBC.
Creating a Data Source with MariaDB Connector/ODBC on Windows
To create a data source on Windows, you would use the ODBC Data Source Administrator.
If you are using the 64-bit version of MariaDB Connector/ODBC, then make sure you use the 64-bit version of ODBC Data Source Administrator. Similarly, if you are using the 32-bit version of MariaDB Connector/ODBC, then make sure you use the 32-bit version of ODBC Data Source Administrator.
To open the ODBC Data Source Administrator in Windows 10:
- On the Start page, type ODBC Data Sources. The ODBC Data Sources Desktop App should appear as a choice.
To open the ODBC Data Source Administrator in Windows 7:
- On the Start menu, click Control Panel.
- In Control Panel, click Administrative Tools.
- In Administrative Tools, click Data Sources (ODBC).
To open the ODBC Data Source Administrator in Windows Server 2008:
- On the Start menu, point to Administrative Tools, and then click Data Sources (ODBC).
Creating a Data Source with MariaDB Connector/ODBC on Linux
Linux uses UnixODBC as a Driver Manager. To create a data source on Linux, there are two steps:
- First, configure UnixODBC to recognize MariaDB Connector/ODBC as a Driver .
- Second, configure UnixODBC with a Data Source Name (DSN) for your MariaDB Server.
You will need to ensure that UnixODBC has been installed before you can perform these steps.
Configuring MariaDB Connector/ODBC as a UnixODBC Driver on Linux
The first step is to configure UnixODBC to recognize MariaDB Connector/ODBC as a Driver . To configure the Driver , you can use the odbcinst tool, which can add a configuration entry for MariaDB Connector/ODBC to the system’s global /etc/odbcinst.ini file.
For example, create a template file similar to the following, with a name like MariaDB_odbc_driver_template.ini :
And then install it to the system’s global /etc/odbcinst.ini file with the following command:
At this point, you should be able to connect to MariaDB by using the Driver with the SQLDriverConnect function. To connect with SQLDriverConnect , you would need to specify Driver=
See Parameters for connection string options.
Configuring a DSN with UnixODBC on Linux
The second step is to configure UnixODBC with a Data Source Name (DSN) for your MariaDB Server. A DSN allows you to centrally configure all of your server’s connection parameters, so that you can easily configure how to connect to your server in your environment. To configure the DSN , you can use the odbcinst tool, which can add a configuration entry for the given data source to the system’s global /etc/odbc.ini file or your user’s local
For example, create a template file similar to the following, with a name like MariaDB_odbc_data_source_template.ini :
And then you can install it to the system’s global /etc/odbc.ini file with the following command:
Or you can install it to your user’s local
/.odbc.ini file with the following command:
At this point, you should be able to connect to MariaDB by using the DSN with either SQLConnect or the SQLDriverConnect functions. To connect with SQLConnect , you would have to provide MariaDB-server as the ServerName parameter. To connect with SQLDriverConnect , you would have to provide DSN=
See Parameters for connection string options.
UnixODBC also provides a GUI to add DSNs . However, MariaDB Connector/ODBC doesn’t yet support this GUI interface for adding DSNs .
Verifying a DSN Configuration with UnixODBC on Linux
You can verify that a DSN is properly configured with UnixODBC on Linux by using the isql utility.
For example, if the DSN is called MariaDB-server , then we can verify that it works properly by executing the following:
Changing UnixODBC’s Configuration File Paths
You can also change the paths that unixODBC uses for its configuration files by changing some environment variables. For example:
- ODBCSYSINI — Overloads path to unixODBC configuration files. By default equals to /etc .
- ODBCINSTINI — Overloads the name of the drivers configuration file. It is relative to ODBCSYSINI and by default set to odbcinst.ini .
- ODBCINI — Overloads the path to user configuration file. By default it is set to
Creating a Data Source with MariaDB Connector/ODBC on Mac OS X
Mac OS X uses iODBC as a Driver Manager. To create a data source on Mac OS X, there are two primary ways to do it:
- You can create a data source with the iODBC Administrator GUI tool.
- You can create a data source by manually editing the iODBC configuration file.
Creating a Data Source with iODBC Administrator on Mac OS X
iODBC Administrator is not installed by default. In order to use it, you need to dowload it from iODBC’s download page and then install it.
Creating a Data Source with iODBC on Mac OS X
The steps to create a data source with iODBC on Mac OS X can be found here. There are essentially two steps:
- First, configure iODBC to recognize MariaDB Connector/ODBC as a Driver .
- Second, configure iODBC with a Data Source Name (DSN) for your MariaDB Server.
Configuring MariaDB Connector/ODBC as a iODBC Driver on Mac OS X
The first step is to configure iODBC to recognize MariaDB Connector/ODBC as a Driver .
The iODBC Driver configuration file might be at one of these paths:
- The path specified by the $ODBCINSTINI environment variable.
/Library/ODBC/odbcinst.ini
MariaDB Connector/ODBC’s PKG package automatically configures itself as a Driver in /Library/ODBC/odbcinst.ini , so you can most likely skip this step.
To add MariaDB Connector/ODBC as a Driver , the configuration file would look something like the following:
Configuring a DSN with iODBC on Mac OS X
The second step is to configure iODBC with a Data Source Name (DSN) for your MariaDB Server. A DSN allows you to centrally configure all of your server’s connection parameters, so that you can easily configure how to connect to your server in your environment.
The iODBC DSN configuration file might be at one of these paths:
- The path specified by the $ODBCINI environment variable.
/Library/ODBC/odbc.ini
To add a DSN that uses MariaDB Connector/ODBC, the configuration file would look something like the following:
Verifying a DSN Configuration with iODBC on Mac OS X
You can verify that a DSN is properly configured with iODBC on Mac OS X by using the iodbctest utility.
For example, if the DSN is called MariaDB-server , then we can verify that it works properly by executing the following:
About MariaDB Connector/ODBC
MariaDB Connector/ODBC is a database driver that uses the industry standard Open Database Connectivity (ODBC) API. Some of the key features of the driver are:
- It is LGPL-licensed.
- It is compliant with the ODBC 3.5 standard.
- It can be used as a drop-in replacement for MySQL Connector/ODBC.
- It supports both Unicode and ANSI modes.
- It primarily uses the MariaDB/MySQL binary protocol (i.e. server-side prepared statements).
The current release series are:
- MariaDB Connector/ODBC 3.1 is the current stable release series.
- MariaDB Connector/ODBC 3.0 and 2.0 are both previous stable release series.
Recent Releases
The most recent Stable (GA) release of MariaDB Connector/ODBC is:
MariaDB Connector/ODBC 3.1.11
Date | Release | Status | Release Notes | Changelog |
---|---|---|---|---|
11 Dec 2020 | MariaDB Connector/ODBC 3.1.11 | Stable (GA) | Release Notes | Changelog |
20 Oct 2020 | MariaDB Connector/ODBC 3.1.10 | Stable (GA) | Release Notes | Changelog |
30 Jun 2020 | MariaDB Connector/ODBC 3.1.9 | Stable (GA) | Release Notes | Changelog |
Contents
Installing MariaDB Connector/ODBC
MariaDB Connector/ODBC packages can be downloaded by selecting your desired version from the following page:
MariaDB Connector/ODBC packages can also be downloaded by selecting ODBC connector as the Product on the following page:
See the instructions below for information on how to install the MariaDB Connector/ODBC package for your operating system.
Installing MariaDB Connector/ODBC on Windows
To install MariaDB Connector/ODBC on Windows, we distribute MSI packages. The MSI installation process is fairly straightforward.
MariaDB Connector/ODBC supports the built-in ODBC Driver Manager on Windows, so nothing else needs to be installed. The MSI installation process will even take care of registering MariaDB Connector/ODBC with the ODBC Driver Manager, so that it is ready to use immediately.
It is generally a good idea to download and install both the 32-bit and 64-bit MSI packages. Otherwise, the ODBC Driver Manager may sometimes load the wrong version of the driver for your application, which can cause errors like the following:
Installing MariaDB Connector/ODBC on Linux
To install MariaDB Connector/ODBC on Linux, we currently only distribute binary tarball packages.
The installation process is fairly easy. First, you need to extract the files from the binary tarball. Then, you need to install the driver’s shared library to the appropriate place in your system. The driver’s shared library is called libmaodbc.so and it is located in either the lib directory or the lib64 directory, depending on whether you downloaded a 32-bit or 64-bit package. The driver’s shared library can be installed anywhere, but for simplicity, the instructions below will assume that you are installing it to /usr/lib64 , which is a common directory for 64-bit shared libraries on many Linux distributions.
Installation steps for some common Linux distributions are shown below. The commands would be similar for other Linux distributions. However, the URL of the package and the installation path may be different.
Installing MariaDB Connector/ODBC on RHEL/CentOS
The following commands would download and install MariaDB Connector/ODBC 3.1.7 on RHEL or CentOS 7:
Installing MariaDB Connector/ODBC on Debian/Ubuntu
The following commands would download and install MariaDB Connector/ODBC 3.1.7 on Debian or Ubuntu:
These steps may not work on the following operating system versions due to the packaging bug ODBC-278:
- Debian 9 (Stretch)
- Debian 10 (Buster)
- Ubuntu 19.10 (Eoan Ermine)
- Ubuntu 20.04 LTS (Focal Fossa)
Installing MariaDB Connector/ODBC on Mac OS X
To install MariaDB Connector/ODBC on Mac OS X, we distribute PKG packages for releases starting with MariaDB Connector/ODBC 3.1.
MariaDB Connector/ODBC supports the built-in iODBC Driver Manager on Mac OS X, so nothing else needs to be installed.
Installing MariaDB Connector/ODBC from Source
See Building MariaDB Connector/ODBC from Source for information on how to build MariaDB Connector/ODBC from source.
Installing UnixODBC on Linux
In order to use MariaDB Connector/ODBC on Linux, you will also need to install a supported Driver Manager. The only Driver Manager that we currently support on Linux is UnixODBC. In most Linux distributions, you can install UnixODBC by using your Linux distribution’s package manager.
For example, the following command would install the unixODBC package on RHEL, CentOS, and similar Linux distributions:
And the following command would install the unixodbc and odbcinst packages on Debian, Ubuntu, and similar Linux distributions:
If you plan to compile an application from source against MariaDB Connector/ODBC and UnixODBC, then you also need the development header files that define the ODBC API function prototypes, ODBC data types, etc. In most Linux distributions, you can install these UnixODBC development files by using your Linux distribution’s package manager.
For example, the following command would install the unixODBC-devel package on on RHEL, CentOS, and similar Linux distributions:
And the following command would install the unixodbc-dev package on on Debian, Ubuntu, and similar Linux distributions:
If you can’t find the UnixODBC packages with your Linux distribution’s package manager, then you may want to look at the download page at UnixODBC.org for other installation options.
Creating a Data Source with MariaDB Connector/ODBC
See Creating a Data Source with MariaDB Connector/ODBC for information on how to create a data source.
Installing Client Authentication Plugins
In MariaDB Connector/ODBC 3.1 and later, MariaDB Connector/ODBC bundles client authentication plugins with the connector.
In MariaDB Connector/ODBC 3.0 and before, MariaDB Connector/ODBC does not bundle client authentication plugins with the connector.
The connector will need to use client authentication plugins in the following scenarios:
- The server uses the pam authentication plugin.
- The server uses the gssapi authentication plugin.
- The server uses the ed25519 authentication plugin.
- You are connecting to a MySQL server that uses one of the SHA-256 authentication plugins—i.e. either the sha256_password or the caching_sha2_password authentication plugins. However, MariaDB Connector/ODBC is more compatible with MariaDB than with MySQL, and it may not yet fully support these MySQL-only authentication plugins. See ODBC-241 for more information.
If you need client authentication plugins in a version which does not bundle them with the connector, then you will also need to install MariaDB Connector/C, which installs the client authentication plugins as shared libraries, which can be used by MariaDB Connector/ODBC.
MariaDB Connector/ODBC can be configured to use MariaDB Connector/C’s client authentication plugins by setting the PLUGINDIR parameter to the MariaDB Connector/C’s plugin directory. The plugin directory can also be specified with the MARIADB_PLUGIN_DIR environment variable.
On Windows, MariaDB Connector/C often installs plugins to one of the following directories:
- C:\Program Files\MariaDB\MariaDB Connector C\lib\plugin
- C:\Program Files (x86)\MariaDB\MariaDB Connector C\lib\plugin
On Linux, MariaDB Connector/C often installs client authentication plugins to one of the following directories:
When you install the client authentication plugins, ensure that they are for the same architecture as your MariaDB Connector/ODBC installation. If your MariaDB Connector/ODBC installation is 64-bit, then you should install 64-bit client authentication plugins. Likewise, if your MariaDB Connector/ODBC installation is 32-bit, then you should install 32-bit client authentication plugins.
Parameters
DSN-Related Parameters
- DSN : Name of the DSN
- Driver : The name of the MariaDB ODBC Driver. On Windows, this must be
for 3.1 drivers, or for versions from other release series, you must use the corresponding version number for that release series. On Linux, either this must be a path to the driver’s shared library or it must match the Driver name that you provided when you configured the Driver with UnixODBC. - Description : Description of the data source.
- SaveFile : Save a string representation of the DSN to this file.
- FileDSN : The file where the string representation of the DSN can be read.
Logging-Related Parameters
- Trace : Whether to enable the ODBC trace log.
- TraceFile : If the ODBC trace log is enabled, then this is the path to the output file.
General Connection Parameters
- SERVER : name or IP of the MariaDB database server. Aliases: SERVERNAME
- USER : user name for database authentication. Aliases: UID ,
- PASSWORD : password for database authentication. Aliases: PWD
- DATABASE : default database. Aliases: DB
- PORT : TCP/IP Port of the database server
- OPTION : For MySQL Connector/ODBC compatibility. Aliases: OPTIONS . Here are used bits meaning:
- 0(1) — Currently is not used
- 1(2) — Tells connector to return the number of matched rows instead of number of changed rows
- 4(16) — See NO_PROMPT
- 5(32) — Forces use of dynamic cursor
- 6(64) — Forbids the use of database.tablename.column syntax
- 11(2048) — Tells connector to use compression protocol
- 13(8192) — See NAMEDPIPE
- 16(65536) — See USE_MYCNF
- 21(2097152) — See FORWARDONLY
- 22(4194304) — See AUTO_RECONNECT
- 26(67108864) — Allows to send multiple statements in one query
- NAMEDPIPE : boolean value(non-zero value is treated as TRUE) determining whether Server is treated as a named pipe name, or as domain name/IP address. Using of NAMEDPIPE is equivalent of setting/resetting of 13th bit(counting from 0, 8192) OPTIONS bit. It has effect on Windows only.
- TCPIP : has reverse meaning with NAMEDPIPE . i.e. setting TCPIP=0 effectively means NamedPipe=1. This keyword is also Windows specific.
- SOCKET : full socket name, if it is specified, server name is disregarded. It has effect on Linux only.
- INITSTMT : SQL command(s) to be run at connection time
- CONN_TIMEOUT : connect timeout in seconds
- AUTO_RECONNECT : enabling/disabling automatic reconnect, the same as setting/resetting 22th(4194304) OPTIONS bit
- NO_PROMPT : suppresses prompt dialog display at the connection time. This has the same meaning as setting/resetting bit #4(16) of the OPTIONS
- CHARSET : connection character set. Connector assumes that all incoming string data is encoded in this character set, and uses it if recoding to/from Unicode(utf16) encoding is required.
- PLUGIN_DIR : Specify the location of client plugins.
- The plugin directory can also be specified with the MARIADB_PLUGIN_DIR environment variable.
- See Installing Client Authentication Plugins for more information.
- USE_MYCNF : whether to read options from the [odbc] option group in the system’s default my.cnf option file.
- Since MariaDB Connector/ODBC relies on MariaDB Connector/C, see Configuring MariaDB Connector/C with Option Files for more information.
- This parameter is available starting with MariaDB Connector/ODBC versions 2.0.19, 3.0.9, and 3.1.1.
- SERVERKEY : Specifies the name of the file which contains the RSA public key of the database server. The format of this file must be in PEM format. This option is used by the caching_sha2_password client authentication plugin.
- This parameter is available starting with MariaDB Connector/ODBC version 3.1.4.
- INTERACTIVE : tells server, that the client is interactive, and it should use interactive_timeout for this connection
- This parameter is available starting with MariaDB Connector/ODBC version 3.1.10.
- FORWARDONLY : forces all cursors to be forward only.
- This parameter is available starting with MariaDB Connector/ODBC version 3.1.10
General Connection Parameters Example
For example, to set these parameters in a connection string via C/C++ code, you could do something like the following:
To set these same parameters in a UnixODBC or iODBC configuration file, you could do something like the following:
TLS-Related Connection Parameters
The following TLS-related connection parameters are available in MariaDB Connector/ODBC 3.0 and later:
- SSLCERT : Defines a path to the X509 certificate file to use for TLS. This parameter requires that you use the absolute path, not a relative path.
- SSLKEY : Defines a path to a private key file to use for TLS. The key file must be unencrypted. This parameter requires that you use the absolute path, not a relative path.
- SSLCA : Defines a path to a PEM file that should contain one or more X509 certificates for trusted Certificate Authorities (CAs) to use for TLS. This parameter requires that you use the absolute path, not a relative path.
- See Secure Connections Overview: Certificate Authorities (CAs) for more information.
- SSLCAPATH : Defines a path to a directory that contains one or more PEM files that should each contain one X509 certificate for a trusted Certificate Authority (CA) to use for TLS. This parameter requires that you use the absolute path, not a relative path. The directory specified by this parameter needs to be run through the openssl rehash command.
- See Secure Connections Overview: Certificate Authorities (CAs) for more information.
- This parameter is only supported if the connector was built with OpenSSL. If the connector was built with GnuTLS or Schannel, then this parameter is not supported. See TLS and Cryptography Libraries Used by MariaDB for more information about which libraries are used on which platforms.
- SSLCIPHER : Defines a list of permitted ciphers or cipher suites to use for TLS..
- SSLVERIFY : Enables (or disables) server certificate verification.
- SSLCRL : Defines a path to a PEM file that should contain one or more revoked X509 certificates to use for TLS. This parameter requires that you use the absolute path, not a relative path.
- See Secure Connections Overview: Certificate Revocation Lists (CRLs) for more information.
- This parameter is only supported if the connector was built with OpenSSL or Schannel. If the connector was built with GnuTLS, then this parameter is not supported. See TLS and Cryptography Libraries Used by MariaDB for more information about which libraries are used on which platforms.
- SSLCRLPATH : Defines a path to a directory that contains one or more PEM files that should each contain one revoked X509 certificate to use for TLS. This parameter requires that you use the absolute path, not a relative path. The directory specified by this parameter needs to be run through the openssl rehash command.
- See Secure Connections Overview: Certificate Revocation Lists (CRLs) for more information.
- This parameter is only supported if the connector was built with OpenSSL. If the connector was built with GnuTLS or Schannel, then this parameter is not supported. See TLS and Cryptography Libraries Used by MariaDB for more information about which libraries are used on which platforms.
- TLSVERSION : Specify which TLS versions are allowed. The value can be a comma-separated list of string names consisting of TLSv1.1, TLSv1.2, and TLSv1.3, or it can be an integer value that represents a bitmap, where TLSv1.1 corresponds to bit 1, TLSv1.2 corresponds to bit 2, and TLSv1.3 corresponds to bit 3.
- This parameter is available starting with MariaDB Connector/ODBC versions 3.0.9 and 3.1.1.
- FORCETLS : Whether to force TLS.
- This parameter is available starting with MariaDB Connector/ODBC versions 3.0.9 and 3.1.1.
- TLSPEERFP : Specify the SHA1 fingerprint of a server certificate for validation during the TLS handshake. Aliases: SSLFP
- This parameter is available starting with MariaDB Connector/ODBC version 3.1.4.
- TLSPEERFPLIST : Specify a file which contains one or more SHA1 fingerprints of server certificates for validation during the TLS handshake. Aliases: SSLFPLIST
- This parameter is available starting with MariaDB Connector/ODBC version 3.1.4.
- TLSKEYPWD : Specify a passphrase for a passphrase-protected private key, as configured by the SSLKEY option. This option is only supported if the connector was built with OpenSSL or GnuTLS. If the connector was built with Schannel, then this option is not supported.
- This parameter is available starting with MariaDB Connector/ODBC version 3.1.8.
TLS-Related Connection Parameters Examples
Two-Way TLS Example
Two-way TLS means that both the client and server provide TLS certificates and keys.
For example, to set these parameters in a connection string via C/C++ code, you could do something like the following:
To set these same parameters in a UnixODBC or iODBC configuration file, you could do something like the following:
One-Way TLS Examples
One-Way TLS with Server Certificate Verification Example
One-way TLS means that only the server provides TLS certificates and keys. Server certificate verification means that the client verifies that the certificate belongs to the server.
For example, to set these parameters in a connection string via C/C++ code, you could do something like the following:
To set these same parameters in a UnixODBC or iODBC configuration file, you could do something like the following:
One-Way TLS without Server Certificate Verification Example
One-way TLS means that only the server provides TLS certificates and keys.
For example, to set these parameters in a connection string via C/C++ code, you could do something like the following:
To set these same parameters in a UnixODBC or iODBC configuration file, you could do something like the following:
Known Issues
Multiple Statement Execution
Multiple statement execution is not fully supported. This means that if you try to prepare a multi-statement query where one of statements depends on the execution result of one of the previous statements, then it may fail. For example, the following may return an error in some versions:
Some bugs related to this have been fixed, such as ODBC-159. If you find similar cases, please report a bug.
Authenticating with PAM
If you try to authenticate with a user account that is configured to use the pam authentication plugin, then you might see one of the following errors.
You might see this error:
Or if the server has the pam_use_cleartext_plugin system variable set, then you might see this error instead:
These errors occur because the pam authentication plugin requires specific client authentication plugins in order to work, and MariaDB Connector/ODBC does not install these plugins. To fix the problem, please install the client authentication plugins.
See ODBC-23 for more information.
Reporting Bugs
If you find a bug, please report it via the ODBC project on MariaDB’s Jira bug tracker.
Source Code
The source code is available at the mariadb-connector-odbc repository on GitHub.
License
GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
For licensing questions, see the Licensing FAQ.