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

0    873    1

Tags:

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

APPLIES TO:

MySQL Connectors - Version 3.51 to 6.8 [Release 3.51 to 6.8]
Oracle Database - Enterprise Edition - Version 11.1.0.6 to 12.1.0.2 [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.
ODBC, UnixODBC, DG4ODBC, MySQL, ODBCINI, Database Link

GOAL

How to connect Oracle to MySQL Server through ODBC database link

SOLUTION

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

| |

+--------------------------------------------------------------------------+

​ /|\

​ |

​ NETWORK

​ |

​ |/

​ +----+

​ | |

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

www.unixodbc.org

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:

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:

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://edelivery.oracle.com/

Step 4

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

https://dev.mysql.com/doc/connector-odbc/en/connector-odbc-configuration-dsn-unix.html

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

Error 3:

[S1000][unixODBC][MySQL][ODBC 5.1 Driver]Access denied for user 'dbs'@'%'

本人提供Oracle(OCP、OCM)、MySQL(OCP)、PostgreSQL(PGCA、PGCE、PGCM)等数据库的培训和考证业务,私聊QQ646634621或微信dbaup66,谢谢!
AiDBA后续精彩内容已被站长无情隐藏,请输入验证码解锁本文!
验证码:
获取验证码: 请先关注本站微信公众号,然后回复“验证码”,获取验证码。在微信里搜索“AiDBA”或者“dbaup6”或者微信扫描右侧二维码都可以关注本站微信公众号。

标签:

Avatar photo

小麦苗

学习或考证,均可联系麦老师,请加微信db_bao或QQ646634621

您可能还喜欢...

发表回复