Fri, 29 May 2020
Using MySQL with Oracle Heterogeneous Services
Oracle Database Gateways allow Oracle client applications to access non-Oracle databases. For example, Oracle SQL Developer and MySQL. Oracle Database Gateways and Heterogeneous Services (built into Oracle) present the appearance of a single, local Oracle database, even though the data might be in Oracle, MySQL, SQL Server and so on.
The Oracle Database Gateway for ODBC (DG4ODBC) transparently integrates ODBC databases with Oracle. ODBC provides a uniform, cross-DBMS interface and insulates applications from the database by using middleware known as an ODBC driver to translate the application's requests into something that the database understands. Because it uses an ODBC driver to link Oracle to the target database, DG4ODBC is not tied to a specific database. This flexible architecture enables Oracle to coexist with any database for which an ODBC driver is available.
By using DG4ODBC, you can immediately use your Oracle applications, both from Oracle and third-parties, to access information in an ODBC database as though it was an Oracle database. Applications do not need to be recoded or reconfigured.
DG4ODBC comes as part of Oracle 11g and later, at no additional cost, and can be used with Oracle 10g and later. To integrate ODBC databases with earlier versions of Oracle, refer to our HSODBC tutorial.
Because DG4ODBC can connect Oracle to any database for which an ODBC driver is available, Oracle refer to DG4ODBC as a generic connectivity agent.
You can use an Easysoft ODBC driver with DG4ODBC to connect Oracle to MySQL. The steps in this guide are for MySQL and Oracle on Linux and UNIX.
Check whether your version of DG4ODBC is 32-bit or 64-bit:
cd $ORACLE_HOME/bin file dg4odbc
filecommand’s output contains "ELF 64-bit LSB executable", or something similar, DG4ODBC is 64-bit, download the 64-bit MySQL ODBC driver for your platform.
Otherwise, download the 32-bit MySQL ODBC driver for your platform.
Install, license and test the MYSQL ODBC driver on the machine where DG4ODBC is installed.
For installation instructions, see the MySQL ODBC driver documentation. Refer to the documentation to see which environment variables you need to set (
SHLIB_PATHdepending on the platform and linker).
Create a DG4ODBC init file. For example:
cd $ORACLE_HOME/hs/admin cp initdg4odbc.ora initmysql.ora
Ensure these parameters and values are present in your init file:
HS_FDS_CONNECT_INFO = mysql_odbc_dsn HS_FDS_SHAREABLE_NAME = /usr/local/easysoft/unixODBC/lib/libodbc.so
Replace mysql_odbc_dsn with name of a MySQL ODBC driver data source that connects to the target MySQL database.
If your MySQL server does not require you to supply a user name and a password, include
HS_FDS_CONNECT_INFOparameter value. For example:
HS_FDS_CONNECT_INFO = "mysql_odbc_dsn;IgnoreAuth=Yes"
- Add this line to increase Oracle / MySQL compatibility:
HS_FDS_QUOTE_IDENTIFIER = FALSE
Add an entry to
$ORACLE_HOME/network/admin/listener.orathat creates a SID_NAME for DG4ODBC. For example:
SID_LIST_LISTENER = (SID_LIST = (SID_DESC= (SID_NAME=mysql) (ORACLE_HOME=oracle_home_directory) (PROGRAM=dg4odbc) (ENVS=LD_LIBRARY_PATH = /usr/local/easysoft/unixODBC/lib: /usr/local/easysoft/lib) ) )
Replace oracle_home_directory with the value of
$ORACLE_HOME. For example,
Add a DG4ODBC entry to
$ORACLE_HOME/network/admin/tnsnames.orathat specifies the SID_NAME created in the previous step. For example:
mysql_connection= (DESCRIPTION= (ADDRESS=(PROTOCOL=TCP)(HOST=oracle_host)(PORT=1521)) (CONNECT_DATA= (SID=mysql)) (HS=OK) )
Start (or restart) the Oracle Listener:
cd $ORACLE_HOME/bin ./lsnrctl stop ./lsnrctl start
- Connect to your Oracle database in SQL*Plus.
In SQL*Plus, create a database link for the target MySQL database. For example:
CREATE PUBLIC DATABASE LINK mysqllink CONNECT TO "dbuser" IDENTIFIED BY "dbpassword" using 'mysql_connection';
Replace dbuser and dbpassword with a valid username and password for the target MySQL database.
– Or, if your MySQL server does not require you to supply a user name and a password:
CREATE PUBLIC DATABASE LINK mysqllink USING 'mysql';