Detailed Overview of Connecting Oracle to MySQL Using DG4ODBC Database Link (Doc ID 1320645.1)

0    576    1


👉 本文共约4296个字,系统预计阅读时间或需17分钟。


MySQL Connectors - Version 3.51 to 6.8 [Release 3.51 to 6.8]
Oracle Database - Enterprise Edition - Version to [Release 11.1 to 12.1]
MySQL Server - Version 5.5 to 5.7 [Release 5.5 to 5.7]
Oracle Database Cloud Schema Service - Version N/A and later
Gen 1 Exadata Cloud at Customer (Oracle Exadata Database Cloud Machine) - Version N/A and later
Information in this document applies to any platform.


How to connect Oracle to MySQL Server through ODBC database link


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] |

| |


​ /|\

​ |


​ |

​ |/

​ +----+

​ | |

​ | [MySQL Server] |

​ | |

​ +-----------------------+

In this article we will configure each component and diagnose problems that are most likely to be encountered during the setup process. NOTE: There are few articles in the internet that skip [ODBC Driver Manager] and connect directly [DG4ODBC] <- - -> [ODBC Driver]. It might work for some

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:

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 -

and click on the 'Download' option.
Follow the steps detailed there to install and configure the driver manager.

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:

Download the latest tar.gz package from the following page:

Unpack the driver into ~/app directory:

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 -

Step 4

Configuring ODBC data source for MySQL Connector/ODBC driver is described here:

So, we will create odbc.ini file in ~/etc:

Step 5 (Optional)

Verifying the ODBC connection using isql command line.

The above output will display if connection has been established successfully. Next, trying to send a simple query to list tables in the database:

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: 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 The solution is to export the directory containing ito LD_LIBRARY_PATH env variable

as shown at the beginning of Step 5.

The following command must not show failing dependencies:

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]:

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.

Step 6:

Configuring tnsnames.ora.

Add the following lines to $ORACLE_HOME/network/admin/tnsnames.ora

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:

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.

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:

Step 10 (Optional)

Checking the service status:

If the above commands report errors check thsnames.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):


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 |



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/

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-



[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:



background_dump_dest string /home/dbs/app/Ora/diag/rdbms/o


\2. HS trace file.

With the current settings the HS trace is disabled. To enable it uncomment the following line in initmyodbc5.ora:


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


The trace file is located in /tmp directory. The name of the file is sql.log.


NOTE:1083703.1 - Primary Note for Oracle Gateway Products
NOTE:561033.1 - How to Configure DG4ODBC on 64bit Unix OS (Linux, Solaris, AIX, HP-UX Itanium) to Connect to Non-Oracle Databases Post Install







  • 18509239930
  • 个人微信

  • 麦老师QQ聊天
  • 个人邮箱
  • 点击加入QQ群
  • 个人微店

  • 回到顶部