How to install and configure MariaDB unixODBC driver

MariaDB unixODBC driver is not available in the Debian package repository at this moment, but you can build and configure it on your own. It requires some additional work, but in the end it is really worth the time.

Install MariaDB server

This step is optional, but it will be useful during testing phase.

Install MariaDB server.

$ sudo apt-get install mariadb-server

I will use the following database server version.

$ apt-cache policy mariadb-server
mariadb-server:
  Installed: 10.1.26-0+deb9u1
  Candidate: 10.1.26-0+deb9u1
  Version table:
 *** 10.1.26-0+deb9u1 500
        500 http://ftp.task.gda.pl/debian stretch/main amd64 Packages
        500 http://security.debian.org/debian-security stretch/updates/main amd64 Packages
        100 /var/lib/dpkg/status

Create minimal set of sample data to test that unixODBC driver works as expected.

$ cat << EOF | sudo mariadb
CREATE USER 'milosz'@'localhost' IDENTIFIED BY 'password';
CREATE DATABASE localdb;
GRANT ALL ON localdb.* TO 'milosz'@'localhost';
USE localdb;
CREATE TABLE IF NOT EXISTS sample_table (varchar_column varchar(50) DEFAULT NULL);
INSERT INTO sample_table (varchar_column) VALUES ('test value');
EOF

Install unixODBC

Install unixODBC software.

$ sudo apt-get install unixodbc unixodbc-dev odbcinst

Install essential utilities

Install required dependencies.

$ sudo apt-get install git checkinstall cmake build-essential libssl1.0-dev

Build MariaDB cient library

This package is required to build unixODBC driver. It overlaps with libmariadb-dev, but provides additional header files that are missing in the mentioned Debian package.

Clone MariaDB client library.

$ git clone https://github.com/MariaDB/mariadb-connector-c.git

Change working directory.

$ cd mariadb-connector-c

Display available tags.

$ git tag
v2.2.1
v2.2.2
v2.2.3
v2.3.0
v2.3.1
v2.3.2
v2.3.3_pre
v3.0-cc-server-integ-0
v3.0.1-beta
v3.0.2
v_2.3.3
v_2.3.4

Checkout the v3.0.2 tag.

$ git checkout tags/v3.0.2

Generate standard UNIX makefiles

$ cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/usr/local -LH
-- Could NOT find CURL (missing:  CURL_LIBRARY CURL_INCLUDE_DIR) 
-- Could NOT find CURL (missing:  CURL_LIBRARY CURL_INCLUDE_DIR) 
SYSTEM processor: x86_64
-- Configuring done
-- Generating done
-- Build files have been written to: /home/milosz/mariadb-connector-c
-- Cache values
// Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.
CMAKE_BUILD_TYPE:STRING=

// Install path prefix, prepended onto install directories.
CMAKE_INSTALL_PREFIX:PATH=/usr/local

// Installation layout. Currently supported options are DEFAULT (tar.gz and zip) and RPM
INSTALL_LAYOUT:STRING=DEFAULT

// Enables use of curl
WITH_CURL:BOOL=ON

// Enables support of dynamic coluumns
WITH_DYNCOL:BOOL=ON

// Enables use of external zlib
WITH_EXTERNAL_ZLIB:BOOL=OFF

// creates libmysql* symbolic links
WITH_MYSQLCOMPAT:BOOL=OFF

// Enables use of TLS/SSL library
WITH_SSL:BOOL=ON

// build test suite
WITH_UNITTEST:BOOL=ON

Compile the source code.

$ make

Create package description.

$ echo "MariaDB ODBC client library" | tee description-pak

Build package.

$ checkinstall --nodoc --pkgname "mariadb-connector-client-library" --pkgversion "3.0.2" --provides "mariadb-connector-client-library" --requires "libssl1.0.2" --requires "mariadb-server" --maintainer "milosz@localhost" --replaces none --conflicts none --install=no -y

checkinstall 1.6.2, Copyright 2009 Felipe Eduardo Sanchez Diaz Duran
           This software is released under the GNU GPL.



*****************************************
**** Debian package creation selected ***
*****************************************

This package will be built according to these values: 

0 -  Maintainer: [ milosz@localhost ]
1 -  Summary: [ MariaDB ODBC client library ]
2 -  Name:    [ mariadb-connector-client-library ]
3 -  Version: [ 3.0.2 ]
4 -  Release: [ 1 ]
5 -  License: [ GPL ]
6 -  Group:   [ checkinstall ]
7 -  Architecture: [ amd64 ]
8 -  Source location: [ mariadb-connector-c ]
9 -  Alternate source location: [  ]
10 - Requires: [ mariadb-server ]
11 - Provides: [ mariadb-connector-client-library ]
12 - Conflicts: [ none ]
13 - Replaces: [ none ]

Enter a number to change any of them or press ENTER to continue: 

Installing with make install...

========================= Installation results ===========================
[ 44%] Built target mariadb_obj
[ 45%] Built target mariadbclient
[ 46%] Built target libmariadb
[ 49%] Built target dialog
[ 51%] Built target mysql_clear_password
[ 53%] Built target mariadb_config
[ 55%] Built target cctap
[ 57%] Built target ma_getopt
[ 59%] Built target view
[ 61%] Built target sqlite3
[ 63%] Built target errors
[ 65%] Built target cursor
[ 67%] Built target performance
[ 69%] Built target charset
[ 71%] Built target t_aurora
[ 73%] Built target thread
[ 74%] Built target async
[ 76%] Built target fetch
[ 78%] Built target connection
[ 80%] Built target t_conc173
[ 82%] Built target basic-t
[ 84%] Built target logs
[ 86%] Built target bulk1
[ 88%] Built target ps
[ 89%] Built target ps_bugs
[ 91%] Built target result
[ 93%] Built target sp
[ 95%] Built target misc
[ 97%] Built target ps_new
[ 99%] Built target features-10_2
[100%] Built target dyncol
Install the project...
-- Install configuration: "RelWithDebInfo"
-- Installing: /usr/local/include/mariadb/mariadb_com.h
-- Installing: /usr/local/include/mariadb/mysql.h
-- Installing: /usr/local/include/mariadb/mariadb_stmt.h
-- Installing: /usr/local/include/mariadb/ma_pvio.h
-- Installing: /usr/local/include/mariadb/ma_tls.h
-- Installing: /usr/local/include/mariadb/mariadb_version.h
-- Installing: /usr/local/include/mariadb/ma_list.h
-- Installing: /usr/local/include/mariadb/errmsg.h
-- Installing: /usr/local/include/mariadb/mariadb_dyncol.h
-- Installing: /usr/local/include/mariadb/mariadb_ctype.h
-- Installing: /usr/local/include/mariadb/mysqld_error.h
-- Installing: /usr/local/include/mariadb/mysql/client_plugin.h
-- Installing: /usr/local/include/mariadb/mysql/plugin_auth_common.h
-- Installing: /usr/local/include/mariadb/mysql/plugin_auth.h
-- Installing: /usr/local/include/mariadb/mariadb/ma_io.h
-- Installing: /usr/local/lib/mariadb/libmariadbclient.a
-- Installing: /usr/local/lib/mariadb/libmariadb.so.3
-- Installing: /usr/local/lib/mariadb/libmariadb.so
-- Installing: /usr/local/lib/mariadb/plugin/dialog.so
-- Installing: /usr/local/lib/mariadb/plugin/mysql_clear_password.so
-- Installing: /usr/local/bin/mariadb_config

======================== Installation successful ==========================

Some of the files created by the installation are inside the home directory: /home

You probably don't want them to be included in the package.
Do you want me to list them?  [n]: n
Should I exclude them from the package? (Saying yes is a good idea)  [n]: n

Copying files to the temporary directory...OK

Stripping ELF binaries and libraries...OK

Compressing man pages...OK

Building file list...OK

Building Debian package...OK

NOTE: The package will not be installed

Erasing temporary files...OK

Writing backup package...OK
OK

Deleting temp dir...OK


**********************************************************************

 Done. The new package has been saved to

 /home/milosz/mariadb-connector-c/mariadb-connector-client-library_3.0.2-1_amd64.deb
 You can install it in your system anytime using: 

      dpkg -i mariadb-connector-client-library_3.0.2-1_amd64.deb

**********************************************************************

Install created package.

$ sudo dpkg -i mariadb-connector-client-library_3.0.2-1_amd64.deb

Change working directory.

$ cd 

Build MariaDB unixODBC driver

Clone MariaDB Connector ODBC.

$ git clone https://github.com/MariaDB/mariadb-connector-odbc.git
Cloning into 'mariadb-connector-odbc'...
remote: Counting objects: 2376, done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 2376 (delta 9), reused 9 (delta 5), pack-reused 2356
Receiving objects: 100% (2376/2376), 2.87 MiB | 581.00 KiB/s, done.
Resolving deltas: 100% (1905/1905), done.

Change working directory.

$ cd mariadb-connector-odbc

Display available tags.

$ git tag
1.0.3
1.0.5
1.0.6
2.0.0
2.0.10
2.0.11
2.0.12
2.0.13
2.0.14
2.0.15
2.0.9
3.0.0
3.0.1
3.0.2

Checkout the 3.0.1 tag. You cannot use 3.0.2 as used client library version does not declare STMT_INDICATOR_IGNORE_ROW (4) tag inside enum_indicator_type enumerated type.

$ git checkout tags/3.0.1

Generate standard UNIX makefiles.

$ cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DWITH_OPENSSL=true -DCMAKE_INSTALL_PREFIX=/usr/local -LH
-- Found MariaDB libraries: /usr/local/lib/mariadb/
-- Found ODBC Driver Manager includes: /usr/include
-- Found ODBC Driver Manager libraries: /usr/lib/x86_64-linux-gnu
-- Checking if SQLColAttribute expects SQLPOINTER FALSE
-- Configuring to build with OpenSSL
-- Configuring tests for linking against the DM library
-- Configurig Test Driver: maodbc_test, Test DSN: maodbc_test, tcp://root@localhost:3306/test socket: 
-- linux
-- License File: /home/milosz/mariadb-connector-c/mariadb-connector-odbc/COPYING
-- ReadMe File: /home/milosz/mariadb-connector-c/mariadb-connector-odbc/README
-- Source Package Filename: mariadb-connector-odbc-3.0.1-beta-src.TGZ
-- Configuring done
-- Generating done
-- Build files have been written to: /home/milosz/mariadb-connector-c/mariadb-connector-odbc
-- Cache values
// Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.
CMAKE_BUILD_TYPE:STRING=Release

// Install path prefix, prepended onto install directories.
CMAKE_INSTALL_PREFIX:PATH=/usr/local

// Path to a file.
MARIADB_BIN_DIR:PATH=/usr/local/bin

// Path to a file.
MARIADB_INCLUDE_DIR:PATH=MARIADB_INCLUDE_DIR-NOTFOUND

// Path to a program.
ODBC_CONFIG:FILEPATH=ODBC_CONFIG-NOTFOUND

// Driver Manager Includes
ODBC_INCLUDE_DIR:PATH=/usr/include

// Driver Manager Libraries
ODBC_LIB_DIR:PATH=/usr/lib/x86_64-linux-gnu

Compile the source code.

$ make

Create package description.

$ echo "MariaDB ODBC driver" | tee description-pak

Build package.

$ checkinstall --nodoc --pkgname "mariadb-connector-odbc" --pkgversion "3.0.1" --provides "mariadb-connector-odbc" --requires "unixodbc,odbcinst,libssl1.0.2" --maintainer "milosz@localhost" --replaces none --conflicts none --install=no -y

checkinstall 1.6.2, Copyright 2009 Felipe Eduardo Sanchez Diaz Duran
           This software is released under the GNU GPL.



*****************************************
**** Debian package creation selected ***
*****************************************

This package will be built according to these values: 

0 -  Maintainer: [ milosz@localhost ]
1 -  Summary: [ MariaDB ODBC driver ]
2 -  Name:    [ mariadb-connector-odbc ]
3 -  Version: [ 3.0.1 ]
4 -  Release: [ 1 ]
5 -  License: [ GPL ]
6 -  Group:   [ checkinstall ]
7 -  Architecture: [ amd64 ]
8 -  Source location: [ mariadb-connector-odbc ]
9 -  Alternate source location: [  ]
10 - Requires: [ unixodbc,odbcinst,libssl1.0.2 ]
11 - Provides: [ mariadb-connector-odbc ]
12 - Conflicts: [ none ]
13 - Replaces: [ none ]

Enter a number to change any of them or press ENTER to continue: 

Installing with make install...

========================= Installation results ===========================
[ 29%] Built target maodbc
[ 33%] Built target connstring
[ 36%] Built target multistatement
[ 38%] Built target result2
[ 41%] Built target catalog2
[ 44%] Built target tran
[ 47%] Built target scroll
[ 50%] Built target use_result
[ 52%] Built target param
[ 55%] Built target catalog1
[ 58%] Built target prepare
[ 61%] Built target basic
[ 63%] Built target datetime
[ 66%] Built target types
[ 69%] Built target desc
[ 72%] Built target blob
[ 75%] Built target keys
[ 77%] Built target bulk
[ 80%] Built target curext
[ 83%] Built target relative
[ 86%] Built target unicode
[ 88%] Built target result1
[ 91%] Built target cursor
[ 94%] Built target error
[ 97%] Built target info
[100%] Built target dyn_cursor
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/lib/libmaodbc.so
-- Installing: /usr/local/./share/doc/mariadb_connector_odbc/COPYING
-- Installing: /usr/local/./share/doc/mariadb_connector_odbc/README

======================== Installation successful ==========================

Some of the files created by the installation are inside the home directory: /home

You probably don't want them to be included in the package.
Do you want me to list them?  [n]: n
Should I exclude them from the package? (Saying yes is a good idea)  [n]: n

Copying files to the temporary directory...OK

Stripping ELF binaries and libraries...OK

Compressing man pages...OK

Building file list...OK

Building Debian package...OK

NOTE: The package will not be installed

Erasing temporary files...OK

Writing backup package...OK
OK

Deleting temp dir...OK


**********************************************************************

 Done. The new package has been saved to

 /home/milosz/mariadb-connector-c/mariadb-connector-odbc/mariadb-connector-odbc_3.0.1-1_amd64.deb
 You can install it in your system anytime using: 

      dpkg -i mariadb-connector-odbc_3.0.1-1_amd64.deb

**********************************************************************

Install created package.

$ sudo dpkg -i mariadb-connector-odbc_3.0.1-1_amd64.deb

Configure MariaDB unixODBC driver

Define a driver.

$ cat << EOF | sudo tee /etc/odbcinst.ini
[MariaDB]
Driver      = libmaodbc.so
Description = MariaDB ODBC Connector
EOF

Configure system-wide data source.

$ cat << EOF | sudo tee /etc/odbc.ini
[localdb]
Description         = MariaDB localdb
Driver              = MariaDB
Database            = localdb
Server              = 127.0.0.1
Uid                 = milosz
Password            = password
Port                = 3306
EOF

Confirm that you can connect to the defined data source.

$ echo | iusql localdb -b

You can now execute query using Open Database Connectivity abstraction layer.

$ echo "select * from sample_table" | iusql localdb -b
+---------------------------------------------------+
| varchar_column                                    |
+---------------------------------------------------+
| test value                                        |
+---------------------------------------------------+

SQLRowCount returns 1
1 rows fetched

Done. You need this package to take advantage of MariaDB using unixODBC. MariaDB client library was needed to compile it, you do not need to install it on a target system.

$ ldd /usr/local/lib/libmaodbc.so
linux-vdso.so.1 (0x00007ffc9d1ca000)
libodbcinst.so.2 => /usr/lib/x86_64-linux-gnu/libodbcinst.so.2 (0x00007efe0cee4000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007efe0cbe0000)
libssl.so.1.0.2 => /usr/lib/x86_64-linux-gnu/libssl.so.1.0.2 (0x00007efe0c977000)
libcrypto.so.1.0.2 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.2 (0x00007efe0c513000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007efe0c174000)
libltdl.so.7 => /usr/lib/x86_64-linux-gnu/libltdl.so.7 (0x00007efe0bf68000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007efe0bd4b000)
/lib64/ld-linux-x86-64.so.2 (0x0000558872439000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007efe0bb47000)

Connection parameters are described at About MariaDB Connector/ODBC.

Milosz Galazka's Picture

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system. He is also open for new opportunities and challenges.

Gdansk, Poland https://sleeplessbeastie.eu