Install ODBC on Ubuntu 16.04 – How to Install ODBC on Ubuntu 16.04 LTS

16.04MySQLodbc

After installing a fresh new copy of Ubuntu 16.04, I tried to install MySQL ODBC as per the official documentation at https://help.ubuntu.com/community/ODBC:

# apt-get install libmyodbc
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package libmyodbc is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'libmyodbc' has no installation candidate

I can see this is getting off to a great start!

Searching the package repository for ODBC hasn't been particularly helpful either. This is a very important part of any modern Linux system! Where did it go?!

PS: Updating the documentation at help.ubuntu.com would be nice too!

Edited to add: Also, it seems that the driver file libmyodbc.so doesn't exist on this version of Ubuntu.

Best Answer

Download directly from dev.mysql.com: https://dev.mysql.com/downloads/connector/odbc/

Select Ubuntu 16.04 64 bit or 32 bit (probably 64 bit), download the TAR ball, then copy the file libmyodbc5a.so to /usr/lib/x86_64-linux-gnu/odbc/

then, create /etc/odbcinst.ini

[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc5a.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libodbcmyS.so
FileUsage = 1

and /etc/odbc.ini

[my-connector]
Description           = MySQL connection to  database
Driver                = MySQL
Database              = mydb
Server                = localhost
User             = dbuser
Password              = dbpass
Port                  = 3306
Socket                = /var/run/mysqld/mysqld.sock

Note that the username tag is User (and not username as seen in some examples) and the socket is under /var/run and not under /var/lib

echo "select 1" | isql -v my-connector

then worked for me

Related Question