There are a lot of tutorials out there describing how to get ODBC work with MySQL under Linux. Unfortunately, most of them were not mentioned to be tutorials and their solutions often do not work reliably and stable.
The following has been tested on a Ubuntu 14.04 machine (MySQL 5.5.37, Apache 2.4.7, PHP 5.5.9, unixODBC 2.2.14) and works stable until now.
Make sure you have root access to your system, either by switching to root user:
su root
or by adding the „sudo“ prefix to each command:
sudo ls sudo vi ...
Install and configure MySQL:
apt-get install mysql-server mysql-client
Install ODBC drivers:
apt-get install libmyodbc unixodbc-bin
Lookup the ODBC driver’s location:
find / -name 'lib*odbc*.so' OUTPUT (BEISPIEL): /usr/lib/i386-linux-gnu/odbc/libodbcnnS.so /usr/lib/i386-linux-gnu/odbc/libodbctxtS.so /usr/lib/i386-linux-gnu/odbc/libodbcdrvcfg1S.so /usr/lib/i386-linux-gnu/odbc/libodbcmyS.so /usr/lib/i386-linux-gnu/odbc/liboraodbcS.so /usr/lib/i386-linux-gnu/odbc/libodbcpsqlS.so /usr/lib/i386-linux-gnu/odbc/liboplodbcS.so /usr/lib/i386-linux-gnu/odbc/libodbcminiS.so /usr/lib/i386-linux-gnu/odbc/libmyodbc.so /usr/lib/i386-linux-gnu/odbc/libodbcdrvcfg2S.so
Create your custom ODBC installation file:
vi /etc/odbcinst.ini
Put this in your odbcinst.ini:
[myodbc_mysql] Description = ODBC for MySQL Driver = /usr/lib/i386-linux-gnu/odbc/libmyodbc.so Setup = /usr/lib/i386-linux-gnu/odbc/libodbcmyS.so UsageCount = 1
Lookup the MySQL socket path:
mysqladmin -u root -p version
OUTPUT (EXAMPLE):
Server version 5.5.37-0ubuntu0.14.04.1
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/run/mysqld/mysqld.sock
Uptime: 7 hours 14 min 15 sec
Create your ODBC configuration file:
vi /etc/odbc.ini
Put this in your odbc.ini:
[myodbc_mysql_dsn] # this is your system DSN Description = description of your DSN Driver = myodbc_mysql # custom driver name Server = localhost # or external IP if needed Port = 3306 # or custom port if needed Socket = /var/run/mysqld/mysqld.sock # socket, see above Database = mysqldb1 # MySQL DB name or empty Option = 3 ReadOnly = No
Install the ODBC driver:
odbcinst -i -d -f /etc/odbcinst.ini
Install your system DSN:
odbcinst -i -s -l -f /etc/odbc.ini
Test if your system DSN was installed successfully:
odbcinst -s -q OUTPUT (EXAMPLE): [myodbc_mysql_dsn]
Test if you can connect to your MySQL database via ODBC:
isql -v myodbc_mysql_dsn MYSQLUSER MYSQLUSERPASSWORD
OUTPUT (EXAMPLE):
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+