Oracle database server uses DG4ODBC as the data gateway for connecting to non-Oracle RDBMS. This requires the proper setup for all components involved in transferring data from Oracle to MySQL and back. These components interact with each other in the following way: +--------------------------------------------------------+ | [ORACLE] <---> [DG4ODBC] <---> [ODBC Driver Manager] <---> [ODBC Driver] | drivers such as DataDirect or specific configurations, but beware that MySQL [ODBC Driver] (versions 3.51.x and 5.1.x) is not supposed to be loaded directly. The recommended driver manager is UnixODBC v.2.2.14 or newer. Configuring ODBC connections in 32-bit OS might be slightly easier than in 64-bit OS. The latter can execute 32 and 64-bit code and more attention must be paid to the components versions. In other words, when configuring ODBC you cannot mix 32-bit and 64-bit components within the Client Host. This is so because 32-bit binaries code can only load 32-bit binaries and 64-bit binaries can only load 64-bit binaries. [MySQL Server] is always independent because all communication with the driver is done through the network protocol. You have the choice to place [MySQL Server] on or on another physical host in the network . In any case, the bit depth of [MySQL Server] executable is not important. Step 1 We shall start from determining if [Oracle] and [DG4ODBC] are 32/64-bits: $ file $ORACLE_HOME/bin/dg4odbc /home/dbs/app/Ora/product/11.2.0/dbhome_1/bin/dg4odbc: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped The above command output says that we must use 64-bit [ODBC Driver Manager] and 64-bit [ODBC Driver] Step 2 Getting and installing ODBC Driver Manager. You should download and install the latest version of the UnixODBC driver manager from the site - Step 3 Getting and installing [ODBC Driver]. Similar to UnixODBC, it is possible to have several different versions of MySQL Connector/ODBC driver. Installing the driver from tar.gz package does not require root privileges and allows installing the driver at custom locations, so we will do so. More details about installing MySQL Connector/ODBC can be found here: http://dev.mysql.com/doc/refman/5.5/en/connector-odbc-installation-binary-unix.html Download the latest tar.gz package from the following page: http://dev.mysql.com/downloads/connector/odbc/#downloads Unpack the driver into ~/app directory: $ cd ~/app $ gunzip -c .tar.gz | tar xvf - This command creates the connector directory and extracts all needed files in it. Create a symbolic link with a shorter name: $ ln -s myodbc- The latest versions of all the MySQL software can be downloaded from - https://dev.mysql.com/downloads/mysql/ Step 4 Configuring ODBC data source for MySQL Connector/ODBC driver is described here: http://dev.mysql.com/doc/refman/5.5/en/connector-odbc-configuration-dsn-unix.html So, we will create odbc.ini file in ~/etc: [myodbc5] Driver = /home/dbs/app/myodbc-x.x.x/lib/libmyodbc5.so Description = Connector/ODBC x.x Driver DSN SERVER = xxx.xxx.xxx.xxxx PORT = 3306 USER = mysql_user PASSWORD = ***** DATABASE = test OPTION = 0 TRACE = OFF +---------------------------------------------------------------------------+ | NOTE: Database names are case sensitive in MySQL, so mind what you put | | in DATABASE parameter. 'DATABASE = test' and 'DATABASE = TEST' will point | | to different databases. It may cause an error because of trying to use a | | non-existing database. This error may occur in a system where file names | | are case sensitive (Linux/Unix systems) | | Parameter names, however, are not case sensitive: | | 'DATABASE = test' and 'database = test' are equal. | +---------------------------------------------------------------------------+ Step 5 (Optional) Verifying the ODBC connection using isql command line. $ export ODBCINI=/home/dbs/etc/odbc.ini $ export LD_LIBRARY_PATH=/home/dbs/app/unixodbc-x.x.x/lib:$LD_LIBRARY_PATH $ cd ~/app/unixodbc-x.x.x/bin/ $ ./isql myodbc5 -v +---------------------------------------+ | Connected! | | | | sql-statement | | help [tablename] | | quit | | | +---------------------------------------+ The above output will display if connection has been established successfully. Next, trying to send a simple query to list tables in the database: SQL> show tables; +-----------------------------------------------------------------+ | Tables_in_test | +-----------------------------------------------------------------+ | tab1 | | tab2 | +-----------------------------------------------------------------+ SQLRowCount returns 2 2 rows fetched That was the good scenario when everything went smoothly. However, you might get the following errors: Error 1: [IM002][unixODBC][Driver Manager]Data source name not found, no default driver specified ISQL]ERROR: Could not SQLConnect error usually comes if ODBCINI variable is not pointing to the correct odbc.ini file. To fix this error try: $ cat $ODBCINI The command should display the contents of odbc.ini file with all settings we have configured on Step 4. If the file is there and the same error comes again, check the data source name. The parameter name for isql must be exactly the same as the section name in odbc.ini file. Error 2: ./isql: error while loading shared libraries: libodbc.so.1: cannot open shared object file: No such file or directory This error means that LD_LIBRARY_PATH is set wrong and the linker cannot find the main UnixODBC [Driver Manager] library libodbc.so. The solution is to export the directory containing libodbc.so ito LD_LIBRARY_PATH env variable as shown at the beginning of Step 5. The following command must not show failing dependencies: $ ldd isql linux-vdso.so.1 => (0x00007fffe4ffc000) libodbc.so.1 => /home/dbs/app/unixodbc-2.2.14/lib/libodbc.so.1 (0x00002ae5263e8000) libdl.so.2 => /lib64/libdl.so.2 (0x00000036b1c00000) libreadline.so.5 => /usr/lib64/libreadline.so.5 (0x00000036b1000000) libncurses.so.5 => /usr/lib64/libncurses.so.5 (0x00000036c4400000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00000036b2000000) libc.so.6 => /lib64/libc.so.6 (0x00000036b1400000) /lib64/ld-linux-x86-64.so.2 (0x00000036b0c00000) Error 3: [S1000][unixODBC][MySQL][ODBC 5.1 Driver]Access denied for user 'dbs'@'%' (using password: YES) [ISQL]ERROR: Could not SQLConnect In some cases this error message is not obvious. The user name and password might be correct and mysql command line might work perfectly with the user name and password specified in odbc.ini file. Check the database name in odbc.ini file (DATABASE parameter). As explained in the note on Step 4, the database names are case sensitive in MySQL and the connection might be rejected because the database does not exist or user has no privileges to access a database with this name. Checking the connectivity from mysql command line is a good idea too. +---------------------------------------------------------------------------+ | NOTE: mysql command line does not use ODBC, so it might work even if ODBC | | fails. The idea of this check is to make sure we provided the correct | | connection credentials to ODBC driver. | +---------------------------------------------------------------------------+ mysql command line should use EXACTLY the same user name, host, password, port and be executed on the same host with [Oracle] and [DG4ODBC]: $ mysql "user=mysql_user "password=****** --host=10.0.0.1 --port=3306 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.1.52-community-log MySQL Community Server (GPL) Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL v2 license Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +------------------------+ | Database | +------------------------+ | information_schema | | entitytest | | mysql | | test | | test2 | | test_db | +------------------------+ 6 rows in set (0.07 sec) Step 6: Configuring tnsnames.ora. Add the following lines to $ORACLE_HOME/network/admin/tnsnames.ora myodbc5 = (DESCRIPTION= (ADDRESS= (PROTOCOL=TCP) (HOST=localhost) (PORT=1521) ) (CONNECT_DATA= (SID=myodbc5)) (HS=OK) ) Step 7: Configuring listener.ora Open $ORACLE_HOME/network/admin/listener.ora in a text editor, find SID_LIST_LISTENER definition and add a new entry for myodbc5: SID_LIST_LISTENER= (SID_LIST= (SID_DESC= (SID_NAME=myodbc5) (ORACLE_HOME=/home/dbs/app/Ora/product/11.2.0/dbhome_1) (PROGRAM=dg4odbc) (ENV="LD_LIBRARY_PATH=/home/dbs/app/unixodbc-2.2.14/lib:/home/dbs/app/Ora/product/11.2.0/dbhome_1/lib") ) ) We strongly recommend to add the LD_LIBRARY_PATH to the listener.ora file to avoid any conflicts with already existing ODBC driver managers. The LD_LIBRARY_PATH must contain the fully qualified path to the $ORACLE_HOME/lib and also the library paths of the ODBC driver manager and the ODBC driver itself. Step 8: Configuring gateway init.ora file. This file does not exist and you have to create it. In listener.ora, tnsnames.ora we use the name myodbc5 just for convenience, but it can be literally anything. The init file (initmyodbc5.ora) is a different story because HS_FDS_CONNECT_INFO is the DSN name in odbc.ini. $ vi $ORACLE_HOME/hs/admin/initmyodbc5.ora HS_FDS_CONNECT_INFO=myodbc5 # Data source name in odbc.ini HS_FDS_TRACE_LEVEL=OFF HS_FDS_SHAREABLE_NAME=/home/dbs/app/unixodbc-2.3/lib/libodbc.so HS_FDS_SUPPORT_STATISTICS=FALSE HS_LANGUAGE=AMERICAN_AMERICA.WE8ISO8859P15 # # ODBC env variables set ODBCINI=/home/dbs/etc/odbc.ini +---------------------------------------------------------------------------+ NOTE: HS_FDS_SHAREABLE_NAME must point to the [ODBC Driver Manager] library. It is an error to put there the [ODBC Driver] library. The [ODBC Driver] DSN is referenced in HS_FDS_CONNECT_INFO=myodbc5. +---------------------------------------------------------------------------+ +---------------------------------------------------------------------------+ | NOTE: UnixODBC [ODBC Driver Manager] might not support any character set | | used in Oracle, so the connection string will be corrupted. | | To avoid the connection string corruption it is recommended to set | | HS_LANGUAGE parameter. I the present case AMERICAN_AMERICA.WE8ISO8859P15 | | worked ok | +---------------------------------------------------------------------------+ Step 9 Applying the settings in the configuration files. The listeners must be restarted in order to pick up the changes we just made into tnsnames.ora, listener.ora and initmyodbc5.ora: $ lsnrctl stop $ lsnrctl start +---------------------------------------------------------------------------+ NOTE: The start status has to contain information about the service: ......... | Services Summary... Service "myodbc5" has 1 instance(s). Instance "myodbc5", status UNKNOWN, has 1 handler(s) for this service... The command completed successfully +---------------------------------------------------------------------------+ Step 10 (Optional) Checking the service status: $ lsnrctl status LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 06-MAY-2011 19:42:10 Copyright (c) 1991, 2009, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost.localdomain)(PORT=1521))) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production Start Date 06-MAY-2011 19:41:39 Uptime 0 days 0 hr. 0 min. 30 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /home/dbs/app/Ora/product/11.2.0/dbhome_1/network/admin/listener.ora Listener Log File /home/dbs/app/Ora/diag/tnslsnr/dbs-pc/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost.localdomain)(PORT=1521))) Services Summary... Service "myodbc5" has 1 instance(s). Instance "myodbc5", status UNKNOWN, has 1 handler(s) for this service... The command completed successfully The command prints the status of "myodbc5" service. UNKNOWN is not a problem in this case because we have not tried using the service yet. Pinging: $ tnsping myodbc5 TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 06-MAY-2011 19:42:22 Copyright (c) 1997, 2009, Oracle. All rights reserved. Used parameter files: Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION= (ADDRESS= (PROTOCOL=TCP) (HOST=localhost) (PORT=1521)) (CONNECT_DATA= (SID=myodbc5)) (HS=OK)) OK (10 msec) If the above commands report errors check tnsnames.ora and listener.ora and set them as shown on Step 6-7. Step 11: Creating the database link and getting the data. Start sqlplus and type the following command (user and password are the same as in odbc.ini): SQL> create public database link myodbc5 connect to "mysql_user" identified by "********" using 'myodbc5'; Database link created. SQL> select * from "tab1"@myodbc5; id ---------- txt1 ----------------------------------------------------------------------------- 1 some text 2 some more text DONE! +---------------------------------------------------------------------------+ NOTE: When selecting data from MySQL linked table it is recommended to enclose the table name into double quotes as "tab1" unless MySQL Server is set to ANSI_QUOTES | +---------------------------------------------------------------------------+ THINGS TO CHECK IF SELECT DISPLAYS AN ERROR: Oracle HS provides very little information about the error if it occurs, so be prepared to examine lots of different log files and command outputs. First of all, make sure UnixODBC [ODBC Driver Manager] is loaded in memory. To do so run sqlplus and try to execute SELECT as on Step 11. Open another terminal session without closing sqlplus and type the following command: $ lsof | grep "dg4odbc" | grep "libodbc" dg4odbc 8,3 1753075 3474018 /home/dbs/app/unixodbc-2.2.14/lib/libodbc.so.1.0.0 Next, check if the driver library is loaded: $ lsof | grep "dg4odbc" | grep "libmyodbc" dg4odbc 8,3 5717703 3474035 /home/dbs/app/mysql-connector-odbc-5.1.8-linux- glibc2.3-x86-64bit/lib/libmyodbc5-5.1.8.so WHERE TO LOOK FOR LOG AND TRACE FILES: [Oracle], [DG4ODBC] and [ODBC Driver Manager] write logs that allow to identify problems if connect fails with unknown error. 1. alert.log file. Sqlplus command line shows the current location (directory) of the trace file: SQL> show parameter BACKGROUND_DUMP_DEST NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ background_dump_dest string /home/dbs/app/Ora/diag/rdbms/o rcl/orcl/trace 2. HS trace file. With the current settings the HS trace is disabled. To enable it uncomment the following line in initmyodbc5.ora: HS_FDS_TRACE_LEVEL=user The file is named as myodbc5_xxxxx.trc and located in $ORACLE_HOME/hs/log directory. 3. ODBC trace file is written by [ODBC Driver Manager]. To enable ODBC tracing set the following option for your DSN in odbc.ini TRACE = ON The trace file is located in /tmp directory. The name of the file is sql.log.