This Blog describes how to set up a Database link from an Oracle Database to a MySQL Database. As an example serves an Oracle Standard Edition Two Version 19c (19.14.0) Database with the Standard Edition High Availability (SEHA) configuration on Oracle Linux 8.
Packageinstallation
For the installation two RPM-Packages are needed:
yum install unixODBC
- Download
mysql-connector-odbc-8.0.28-1.el8.x86_64.rpm
rpm -ihv mysql-connector-odbc-8.0.28-1.el8.x86_64.rpm
The package unixODBC
installs the basic libraries including /usr/lib64/libodbc.so
which is needed later and the files /etc/odbc.ini
as well as /etc/odbcinst.ini
. Furthermore the tool /usr/bin/isql
belongs to that package
The package mysql-connector-odbc then installs the specific mysql libraries. The file /etc/odbcinst.ini
is also going to be adjusted
ODBC Configuration
For the next step the ODBC client will be configured. For this, the configuration for one or more connections is entered in /etc/odbc.ini
.
Example:
[TESTMYDB] Description = Test-MYSQL-Datenbank Driver = /usr/lib64/libmyodbc8w.so Trace = no Server = 192.168.168.168 Port = 3306 Database = daten User = TESTUSER Password = passwort
It is important to have the name of the entry (TESTMYDB
) and the correct driver. The driver for a unicode MySQL Database is libmyodbc8w.so
. Otherwise libmyodbc8a.so
can be used for a MySQL Database with a 1-Byte character set.
With this it should be possible to connect to the MySQL database from the server.
isql TESTMYDB TESTUSER passwort
Gateway Installation
For the next step, the Oracle Gateway software will be installed. Unfortunately it is still necessary to unpack the software first and then install it:
cd /u05/share/software unzip LINUX.X64:193000_gateways.zip cd gateways ./runInstaller


In the example the gateway for MS-SQL is also installed. This is not important for this configuration.

Thus the gateway is installed in the directory /u01/app/oracle/product/19c/gwhome_1
.
Gateway Configuration
Three components are responsible for the configuration:
listener.ora
tnsnames.ora
init<GATEWAYNAME>.ora
listener.ora
LISTENER= (DESCRIPTION= (ADDRESS_LIST= (ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)) (ADDRESS=(PROTOCOL=TCP)(HOST=seha01)(PORT=1521)) ) ) SID_LIST_LISTENER = (SID_LIST= (SID_DESC= (SID_NAME=TESTMYDB) (ORACLE_HOME=/u01/app/oracle/product/19/gwhome_1) (PROGRAM=dg4odbc) ) )
The SID_NAME
must correspond to the name in the /etc/odbc.ini
file. Of course there can be further SIDs for databases or further ODBC connections. On the second SEHA server the parameter “HOST
” must be adjusted.
tnsnames.ora
TESTMYDB = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = seha01)(PORT = 1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = seha02)(PORT = 1521)) (CONNECT_DATA = (SID = TESTMYDB) ) (HS = OK) )
For RAC or SEHA databases, the scan address cannot be used here. Instead, the HOSTS
has to be specified explicitly.
The TNS alias may have a different name than the SID, which again must be identical to the entry in /etc/odbc.ini
.
initTESTWEBDB.ora
HS_FDS_CONNECT_INFO = TESTWEBDB #HS_FDS_TRACE_LEVEL = OFF #HS_LANGUAGE = AMERICAN_AMERICA.WE8ISO8859P15 HS_FDS_SHAREABLE_NAME = /usr/lib64/libodbc.so
The name of the file must correspond to the name of the odbc.ini
entry.
It is important that the parameter HS_FDS_SHAREABLE_NAME
is not the ODBC library of MySQL but the so called “ODBC Drive Manager“. In this case it is the libodbc.so
from the unixODBC
package.
Database-Link
After all the preparation, the database link can now be created as usual:
CREATE DATABASE LINK jostest CONNECT TO "TESTUSER" IDENTIFIED BY "password" USING 'TESTMYWEBDB";
With this the connection to the MySQL database should work.
If the following error occurs:
ORA-28500: connection from ORACLE to a non-Oracle system returned this message: [
This is probably because the MySQL database is not a Unicode database. The easiest way to solve the problem is to set the following parameter in the initTESTMYDB.ora
file:
HS_LANGUAGE = AMERICAN_AMERICA.WE8ISO8859P15
When accessing the MySQL databases, please note that tables and databases are usually written in lower case. So it is better to put the database and table names in double quotation marks.
SELECT * FROM "daten"."test"@jostest;
That’s it.
If something is still missing or errors occurred, then please send a short message to me or leave a comment on the blog.
Good luck!
MOHAMED NAINAR
please give the configuration of link to mysql in windows platform
Johannes Ahrends
Sorry Mohamed, but I don’t have any experience on setting up MySQL on Windows. MySQL ist mostly used on Linux OS.
Raj
I have been using oracle gateway 19c for ms sql. We did not have install two rpm’s that is needed for MySQL to setup odbc. Looks oracle did not provide any gateway for MySQL so Extra steps here?
Johannes Ahrends
You are right. We installed the gateway for MS-SQL as well – without any additional packages.