How to access ODBC/MySQL tables from Oracle...


Oralce HS (Heterogeneous Service) can be used to access foreign database via a database link.

On Linux install the following packages:
unixODBC-2.2.14-12.el6_3.x86_64
mysql-connector-odbc-5.1.5r1144-7.el6.x86_64

/etc/odbcinst.ini
[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
UsageCount = 1

/etc/odbc.ini
[TEST]
Driver = /usr/lib64/libmyodbc5.so
DATABASE = <dbname>
DESCRIPTION = <something>
PORT = 3306
SERVER = <hostname>
TRACEFILE = /tmp/myodbc-mysql.trc
TRACE = OFF

> odbcinst -i -d -f /etc/odbcinst.ini
> odbcinst -i -s -l -f /etc/odbc.ini

Check with isql if the odbc connection works properly:
isql -v TEST <username> <password>

Adapt the listener.ora file and restart the listener:
SID_LIST_LISTENER=
 (SID_LIST=
  (SID_DESC=
   (SID_NAME=test)
   (ORACLE_HOME=/app/oracle/product/12.1.0.2/dbhome)
   (PROGRAM=dg4odbc)
  )
)

> lsnrctl stop
> lsnrctl start

Create a file init<DSN>.ora (in that case initTEST.ora) file in /app/oracle/product/12.1.0.2/dbhome/hs/admin:
HS_FDS_CONNECT_INFO = WP
HS_FDS_TRACE_LEVEL = 0
HS_FDS_SHAREABLE_NAME = /usr/lib64/libmyodbc5.so
HS_LANGUAGE=AMERICAN_AMERICA.UTF8
HS_NLS_NCHAR = UCS2
set ODBCINI=/etc/odbc.ini

Create a database link:
SQL> create database link TEST connect to "<username>" identified by "<password>" using 'TEST';

Then you should be able to query foreign ODBC tables from Oracle:
SELECT * FROM "tablename"@TEST

Last update:
2014-09-08 22:56
Author:
Andreas Vogler
Revision:
1.0
Average rating:0 (0 Votes)

You can comment this FAQ

Chuck Norris has counted to infinity. Twice.