6
Sethunath Page 1 5/29/2008 Oracle Heterogeneous Services Configuration for MySQL (With ODBC/OLEDB) Author : Sethunath. U Email : [email protected] References http://birijan.com.np/?q=Oracle+Heterogeneous+Services+(Accessing+ODBC+data+source) : Birijan Maharajan http://articles.techrepublic.com.com/5100-10878_11-5725974.html : Scott Stephens

mysql dblink.pdf

Embed Size (px)

DESCRIPTION

mysql dblink.pdf

Citation preview

Page 1: mysql dblink.pdf

Sethunath Page 1 5/29/2008

Oracle Heterogeneous Services

Configuration for MySQL (With ODBC/OLEDB)

Author : Sethunath. U

Email : [email protected]

References

http://birijan.com.np/?q=Oracle+Heterogeneous+Services+(Accessing+ODBC+data+source) : Birijan Maharajan

http://articles.techrepublic.com.com/5100-10878_11-5725974.html : Scott Stephens

Page 2: mysql dblink.pdf

Sethunath Page 2 5/29/2008

Introduction

Heterogeneous services in Oracle permits connection with non-oracle database

systems. Oracle provides two types of Heterogeneous Services agents, Oracle

Transparent Gateways and Generic Connectivity. This document details Generic

Connectivity which uses Generic Connectivity agents for ODBC and OLEDB which enable

you to use ODBC and OLEDB drivers to access MySQL that have an ODBC or an OLEDB

interface. Any data source compatible with the ODBC or OLEDB standards can be

accessed using a Generic Connectivity agent. As there is no transparent gateway

available for MySQL, it can be used to access MySQL; though with certain

limitations.

Using

Windows XP

Oracle EE 10.2.0.3

MySQL version: 5.0

1. Login to mysql H:\> mysql -u root mysql -p

Enter password: ****

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 10 to server version: 5.0.24a-community-nt

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

2. Grant privileges to root user

mysql> grant usage on *.* to root@localhost with grant option;

Query OK, 0 rows affected (0.05 sec)

3. Create database

mysql> create database oraclecall;

Query OK, 0 rows affected (0.04 sec)

mysql> grant usage on *.* to root@localhost with grant option;

Query OK, 0 rows affected (0.05 sec)

mysql> use oraclecall;

Database changed

4. Create a user “oracle”

This user id will be used to authenticate using ODBC/OLEDB

mysql> grant all on oraclecall.* to 'oracle'@'localhost' identified by 'oracle';

Query OK, 0 rows affected (0.02 sec)

mysql> flush PRIVILEGES;

Query OK, 0 rows affected (0.08 sec)

5. Install MySQL ODBC driver 3.51 and configure as follows

Page 3: mysql dblink.pdf

Sethunath Page 3 5/29/2008

6. Configure Oracle Heterogeneous services for ODBC.

Here it can be configured by two methods. We can use either of these two methods.

6.1 Through OLEDB

Create a UDL file (create a text file called msoracle.udl) and save it.

Doubleclick the file to configure the connectivity and configure it as follows.

Select “Use connection string” and click build to select the data source. Select

the data source we created previously (i.e msora35)

Page 4: mysql dblink.pdf

Sethunath Page 4 5/29/2008

Elf

The UDL file will look like the following

[oledb]

; Everything after this line is an OLE DB initstring

Provider=MSDASQL.1;Password=oracle;Persist Security Info=True;User ID=oracle;Extended

Properties="DATABASE=oraclecall;DESCRIPTION=MySQL ODBC 3.51

Driver;DSN=msora35;OPTION=0;PWD=oracle;PORT=0;SERVER=localhost;UID=oracle;";Initial Catalog=oraclecall

Create the init parameters for Heterogeneous services which will be in

$ORACLE_HOME\hs\admin. Make sure to name it as init<SID>.ora

In our case it will be named as initmsora35.ora. The contents of initmsora35.ora

will be as follows

# This is a sample agent init file that contains the HS parameters that are

# needed for an ODBC Agent.

#

# HS init parameters

HS_FDS_CONNECT_INFO = "UDLFILE=D:/oracle/DB10G/hs/admin/msoracle.udl"

HS_FDS_TRACE_LEVEL = 0

# Environment variables required for the non-Oracle system

#

#set <envvar>=<value>

We can access HS by the SQL*Net listener, not the client. So we must let SQL*Net

know about these services and the programs that proxy Oracle SQL to these ODBC and

OLE DB providers. In the listener.ora file in ORACLE_HOME/network/admin, you should

see an area for SID_LIST_LISTENER, and within that an SID_LIST. In that list, add

the entries for each service, like so # listener.ora Network Configuration File: D:\ORACLE\DB10G\network\admin\listener.ora

# Generated by Oracle configuration tools.

SID_LIST_LISTENER =

(SID_LIST =

(SID_DESC =

(SID_NAME = PLSExtProc)

(ORACLE_HOME = D:\ORACLE\DB10G)

(PROGRAM = extproc)

)

(SID_DESC =

(SID_NAME = msora35) (ORACLE_HOME = D:\ORACLE\DB10G)

(PROGRAM = hsolesql) )

)

LISTENER =

(DESCRIPTION_LIST =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))

(ADDRESS = (PROTOCOL = TCP)(HOST = N7224.ibsplc.com)(PORT = 1521))

)

)

hsolesql program access OLE DB. We will be using the hsolesql program for providers

that can process SQL.The ORACLE_HOME directory directs the SQL*Net listener to the

correct installation for that program. Once you make these changes, restart the

listener by entering the following code at the command line:

Lsnrctl stop

Lsnrctl start

6.2 Through ODBC

Page 5: mysql dblink.pdf

Sethunath Page 5 5/29/2008

In our case it will be named as initmsora35.ora. The contents of initmsora35.ora

will be as follows

# This is a sample agent init file that contains the HS parameters that are

# needed for an ODBC Agent.

#

# HS init parameters

HS_FDS_CONNECT_INFO = msora35

HS_FDS_TRACE_LEVEL = 0

# Environment variables required for the non-Oracle system

#

#set <envvar>=<value>

We can access HS by the SQL*Net listener, not the client. So we must let SQL*Net

know about these services and the programs that proxy Oracle SQL to these ODBC and

OLE DB providers. In the listener.ora file in ORACLE_HOME/network/admin, you should

see an area for SID_LIST_LISTENER, and within that an SID_LIST. In that list, add

the entries for each service, like so # listener.ora Network Configuration File: D:\ORACLE\DB10G\network\admin\listener.ora

# Generated by Oracle configuration tools.

SID_LIST_LISTENER =

(SID_LIST =

(SID_DESC =

(SID_NAME = PLSExtProc)

(ORACLE_HOME = D:\ORACLE\DB10G)

(PROGRAM = extproc)

)

(SID_DESC = (SID_NAME = msora35)

(ORACLE_HOME = D:\ORACLE\DB10G) (PROGRAM = hsodbc)

)

)

LISTENER =

(DESCRIPTION_LIST =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))

(ADDRESS = (PROTOCOL = TCP)(HOST = N7224.ibsplc.com)(PORT = 1521))

)

)

hsolesql program access OLE DB. We will be using the hsolesql program for providers

that can process SQL.The ORACLE_HOME directory directs the SQL*Net listener to the

correct installation for that program. Once you make these changes, restart the

listener by entering the following code at the command line:

Lsnrctl stop

Lsnrctl start

7. Configure tnsnames.ora

Add entries to point to the HS in the ORACLE_HOME/network/admin/tnsnames.ora file:

msora =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))

(CONNECT_DATA = (SID= msora35))

(HS=OK)

)

8. Validate accessibility

Page 6: mysql dblink.pdf

Sethunath Page 6 5/29/2008

A connection test will succeed with TNSPING utility. However, this only checks the

connection up to SQL*Net, and not whether the data is available. For that purpose,

login to oracle and create database links.

D:\> sqlplus / as sysdba

SQL> create public database link mysql

connect to "oracle" identified by "oracle" using 'msora';

Database link created.

SQL> select * from tester@mysql;

id name

---------- ------------------------

10 John

11 Raju

SQL> insert into tester@mysql values (12,'Mukund');

1 row created.

SQL> commit;

Commit complete.

Now, check in mysql

mysql> select * from tester;

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

| id | name |

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

| 10 | John |

| 11 | Raju |

| 12 | Mukund |

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

3 rows in set (0.00 sec)

9. Troubleshooting errors

If you got any error specifying syntax as below, it might be due to

the sql_mode in MySQL database.

ORA-28500: connection from ORACLE to a non-Oracle system returned this message:

[MySQL][ODBC 3.51 Driver][mysqld-4.1.20]You have an error in your SQL syntax;

check the manual that corresponds to your MySQL server version for the right

syntax to use near '"ALL_TABLES"' at line 1

ORA-02063: preceding 2 lines from MYSQL

To solve this issue, execute following to change the sql_mode to

ansi_quotes at session level.

DECLARE

ret INTEGER;

c INTEGER;

BEGIN

c := DBMS_HS_PASSTHROUGH.OPEN_CURSOR@mysql;

DBMS_HS_PASSTHROUGH.PARSE@mysql(c, 'SET SESSION SQL_MODE=ANSI_QUOTES');

ret := DBMS_HS_PASSTHROUGH.EXECUTE_NON_QUERY@mysql(c);

dbms_output.put_line(ret ||' passthrough output');

DBMS_HS_PASSTHROUGH.CLOSE_CURSOR@mysql(c);

END;