Install ODBC on Ubuntu 20.04 , 20.10 and above

There used to easy apt install for ODBC like "apt-get install libmyodbc" , not anymore. You have to do some extra effort now, specially when you are installing Asterisk on Ubuntu + MySQL ( MariaDB ) .

 · 1 min read

There used to easy apt install for ODBC like "apt-get install libmyodbc" , not anymore. You have to do some extra effort now

Follow these steps.


apt install unixodbcapt unixodbc-dev -y

cd ~

wget http://ftp.airnet.ne.jp/mirror/mysql/Downloads/Connector-ODBC/5.3/mysql-connector-odbc-5.3.6-linux-ubuntu15.10-x86-64bit.tar.gz

tar -xvf mysql-connector-odbc-5.3.6-linux-ubuntu15.10-x86-64bit.tar.gz


sudo cp mysql-connector-odbc-5.3.6-linux-ubuntu15.10-x86-64bit/lib/libmyodbc5* /usr/lib/x86_64-linux-gnu/odbc/


sudo mysql-connector-odbc-5.3.6-linux-ubuntu15.10-x86-64bit/bin/myodbc-installer -d -a -n "MySQL" -t "DRIVER=/usr/lib/x86_64-linux-gnu/odbc/libmyodbc5w.so;"


sudo mysql-connector-odbc-5.3.6-linux-ubuntu15.10-x86-64bit/bin/myodbc-installer -s -a -c2 -n "test" -t "DRIVER=MySQL;SERVER=127.0.0.1;DATABASE=mysql;UID=root;PWD=123456"


sudo mysql-connector-odbc-5.3.6-linux-ubuntu15.10-x86-64bit/bin/myodbc-installer -s -a -c2 -n "test" -t "DRIVER=MySQL;SERVER=127.0.0.1;DATABASE=mysql;UID=root;PWD=123456"


Following steps are for testing the connectivity



odbcinst -q -d

odbcinst -q -s

isql test will also give you connected message, make sure that your have correct DB and table otherwise it will throw  "[ISQL]ERROR: Could not SQLConnect".


Create a test python script to test connectivity

apt install python3-pip

pip install --upgrade pyodbc


vim test.py 

add following lines in test.py

----------------------------------

# coding=UTF-8

# by

import pyodbc



try:

  print("connecting ...")

  cnxn = pyodbc.connect("DSN=test")

  cursor = cnxn.cursor()

  rows = cursor.execute("select * from TABLES").fetchall()

  print(rows)

  cursor.close()

  print("done!")

except Exception as e:

  print(repr(e))

---------------------------

chmod 777 test.py

python3 test.py


You will see it connected !!!


Following  are the sample files, in case you need troubleshooting.

https://github.com/ERPGulf/docs/blob/main/odbc.ini

https://github.com/ERPGulf/docs/blob/main/odbcinst.ini




Cloud support

Cloud support team provides hosting related support and technology updates. Cover technology like cloud printing, Cloud PBAX, VoIP, Kubernetes, Ubuntu, Linux etc. Contact us on support@ERPGulf.com

No comments yet

No comments yet. Start a new discussion.

Add Comment