How To Install unixODBC-devel on CentOS 7 and Connect DB2 V9.7
Tags: linux, db2, odbc, centos
Published: 2022-06-06 09:01:51



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/js3n2qcxqzz25pckvdwu.jpeg)

Introduction
In this tutorial we learn how to install unixODBC-devel on CentOS 7.

What is unixODBC-devel
The unixODBC package can be used to access databases through ODBC drivers. If you want to develop programs that will access data through ODBC, you need to install this package. The unixODBC package can be used to access databases through ODBC drivers. If you want to develop programs that will access data through ODBC, you need to install this package.

We can use yum or dnf to install unixODBC-devel on CentOS 7. In this tutorial we discuss both methods but you only need to choose one of method to install unixODBC-devel.
Install unixODBC-devel on CentOS 7 Using yum
Update yum database with yum using the following command.
`sudo yum makecache`

After updating yum database, We can install unixODBC-devel using yum by running the following command:
`sudo yum -y install unixODBC-devel`

Install unixODBC-devel on CentOS 7 Using dnf
If you don't have dnf installed you can install dnf first. Update yum database with dnf using the following command.
`sudo dnf makecache`

After updating yum database, We can install unixODBC-devel using dnf by running the following command:
`sudo dnf -y install unixODBC-devel`

How To Uninstall unixODBC-devel on CentOS 7
To uninstall only the unixODBC-devel package we can use the following command:
`sudo dnf remove unixODBC-devel`

unixODBC-devel Package Contents on CentOS 7`
/usr/include/autotest.h
/usr/include/odbcinst.h
/usr/include/odbcinstext.h
/usr/include/sql.h
/usr/include/sqlext.h
/usr/include/sqltypes.h
/usr/include/sqlucode.h
/usr/include/unixodbc_conf.h
/usr/include/unixodbc_conf_i386.h
/usr/include/uodbc_extras.h
/usr/include/uodbc_stats.h
/usr/lib/libesoobS.so
/usr/lib/libmimerS.so
/usr/lib/libnn.so
/usr/lib/libodbccr.so
/usr/lib/libodbcdrvcfg1S.so
/usr/lib/libodbcdrvcfg2S.so
/usr/lib/libodbcminiS.so
/usr/lib/libodbcnnS.so
/usr/lib/libodbctxtS.so
/usr/lib/liboplodbcS.so
/usr/lib/liboraodbcS.so
/usr/lib/libsapdbS.so
/usr/lib/libtdsS.so
/usr/lib/libtemplate.so
/usr/include/autotest.h
/usr/include/odbcinst.h
/usr/include/odbcinstext.h
/usr/include/sql.h
/usr/include/sqlext.h
/usr/include/sqltypes.h
/usr/include/sqlucode.h
/usr/include/unixodbc_conf.h
/usr/include/unixodbc_conf_x86_64.h
/usr/include/uodbc_extras.h
/usr/include/uodbc_stats.h
/usr/lib64/libesoobS.so
/usr/lib64/libmimerS.so
/usr/lib64/libnn.so
/usr/lib64/libodbccr.so
/usr/lib64/libodbcdrvcfg1S.so
/usr/lib64/libodbcdrvcfg2S.so
/usr/lib64/libodbcminiS.so
/usr/lib64/libodbcnnS.so
/usr/lib64/libodbctxtS.so
/usr/lib64/liboplodbcS.so
/usr/lib64/liboraodbcS.so
/usr/lib64/libsapdbS.so
/usr/lib64/libtdsS.so
/usr/lib64/libtemplate.so
`
Check unixODBC-devel on CentOS 7
`odbcinst -j`

Add DB2 Config on /etc/odbcinst.ini
nano /etc/odbcinst.ini

/etc/odbcinst.ini content :

`[PostgreSQL]
Description     = ODBC for PostgreSQL
Driver          = /usr/lib/psqlodbc.so
Setup           = /usr/lib/libodbcpsqlS.so
Driver64        = /usr/lib64/psqlodbc.so
Setup64         = /usr/lib64/libodbcpsqlS.so
FileUsage       = 1
[MySQL]
Description     = ODBC for MySQL
Driver          = /usr/lib/libmyodbc5.so
Setup           = /usr/lib/libodbcmyS.so
Driver64        = /usr/lib64/libmyodbc5.so
Setup64         = /usr/lib64/libodbcmyS.so
FileUsage       = 1
[ODBC]
Trace           = yes
Tracefile       = /tmp/odbc.log
[DB2]
Description     = DB2 Driver
Driver          = /opt/ibm/db2/V9.7/lib32/libdb2.so
Driver64        = /opt/ibm/db2/V9.7/lib64/libdb2o.so
FileUsage       = 1`

Setting DB2 Connection For ODBC
nano /etc/odbc.ini
/etc/odbc.ini content :

`[ODBC Data Sources]
dbschema = dbschema
[dbschema]
Description = Sample1
Driver = /opt/ibm/db2/V9.7/lib64/libdb2o.so
System = 127.0.0.1 
UserID = username
Password = password
Port = 50000
Naming = 1
DefaultLibraries = QGPL
Database = DATABASE
ConnectionType = 0
CommitMode = 2
ExtendedDynamic = 0
DefaultPkgLibrary = QGPL
DefaultPackage = A/DEFAULT(IBM),2,0,1,0,512
AllowDataCompression = 1
LibraryView = 0
AllowUnsupportedChar = 0
ForceTranslation = 0
Trace = 0`

Testing DB2 Odbc Connection :
`isql -V dbschema`

TroubleShooting :
IF ODBC DB2 connection not connect please http/PHP SELINUX FOR ODBC ALLOW:

`setsebool -P httpd_can_network_connect=1`

IF ODBC DB2 connection not connect cause permission please SeLinux ALLOW/pause :

`setenforce 0`

IF ODBC DB2 Driver issue Error Please Allow Path :
`chcon -R -t httpd_sys_rw_content_t storage
chcon -R -t httpd_sys_rw_content_t /path
chcon -R -t httpd_sys_rw_content_t /opt/ibm/db2/V9.7/lib32/libdb2.so`