1,首先在Oracle所在计算机安装MysqL的Client端软件,并且x86_64和i386版本的都需要安装,以便可以连接MysqL数据库。查看Client安装情况:
得到两条记录,一条是x86_64的,一条是i386的。
如果看到还没有安装MysqL客户端软件,则需要安装:
验证在此Oracle所在计算机是可以连接目标主机MysqL数据库:
2,检查Oracle所在计算机是否已安装MysqL ODBC客户端,并且x86_64和i386版本的都需要安装。
如果没有安装MysqL-connector-odbc,则用下面命令下载和安装:
下载 MysqL-connector-odbc:
安装MysqL-connector-odbc:
得到提示
yum list *.i386|grep libtool
yum install libtool-ltdl.i386
3,在Oracle所在计算机编辑/etc/odbc.ini文件,测试ODBC工作
#odbc.ini内容如下
Driver=/usr/lib64/libmyodbc3.so
Description=MysqL
Server=192.168.1.1(MysqL Server IP)
Port=3306
User= (MysqL Username)
UID= (MysqL Username)
Password= (MysqL PWD)
Database= (MysqL Database Name)
Option=3
Socket=
在命令行中执行下列命令,应能够顺利登入MysqL Client窗口,即证明ODBC功能正常:
4,编辑hs配置文件 vi /ora10g/hs/admin/inittest.ora(注意文件名中蓝色部分为odbc.ini中蓝色名称)
HS_FDS_TRACE_LEVEL = on(正式使用后,不需要排错的时候应设为off)
HS_FDS_TRACE_FILE_NAME = test.trc
HS_FDS_SHAREABLE_NAME=/usr/lib/libmyodbc3.so
set ODBCINI=/etc/odbc.ini
5,编辑Oracle所在计算机的Oracle listener的配置文件,建立一个模拟Oracle Listener的监听方式,为将来建立dblink做准备:
vi /ora10g/network/admin/listener.ora 加入如下语句:
(SID_NAME = test)
(ORACLE_HOME = /ora10g)
(PROGRAM = hsodbc)
(ENVS=LD_LIBRARY_PATH=/ora10g/lib32:/usr/lib64:/ora10g/lib)
)
SID_LIST =
(SID_DESC =
(ORACLE_HOME = /ora10g)
(PROGRAM = extproc)
(GLOBAL_DBNAME=prod)
(SID_NAME=prod)
)
(SID_DESC =
(SID_NAME = test)
(ORACLE_HOME = /ora10g)
(PROGRAM = hsodbc)
(ENVS=LD_LIBRARY_PATH=/ora10g/lib32:/usr/lib64:/ora10g/lib)
)
)
LISTENER = (
DESCRIPTION_LIST =
(DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
(ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521)) )
)
执行lsnrctl reload使Listener生效:
lsnrctl reload
LSNRCTL for Linux: Version 10.2.0.4.0 - Production on 09-FEB-2009 13:59:38 Copyright (c) 1991,2007,Oracle.
All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
The command completed successfully
lsnrctl status
LSNRCTL for Linux: Version 10.2.0.4.0 - Production on 12-FEB-2009 08:56:00
Copyright (c) 1991,Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.4.0 - Production
Start Date 03-JAN-2009 03:47:39
Uptime 40 days 5 hr. 8 min. 20 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /ora10g/network/admin/listener.ora
Listener Log File /ora10g/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc",status UNKNOWN,has 1 handler(s) for this service...
Service "test" has 1 instance(s).
Instance "test",has 1 handler(s) for this service...
The command completed successfully
6,编辑Oracle所在计算机中的tnsnames.ora文件,便于建立dblink。注意,此tnsnames的配置可以支持tnsping,但是不能支持sqlplus登录,只用于dblink:
test =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
(CONNECT_DATA =
(SID = test)
)
(HS = OK)
)
7,在Oracle Database建立dblink:
connect to "MysqL username" identified by "MysqL pwd"
using '(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP) (HOST = 127.0.0.1) (PORT =1521) )
(CONNECT_DATA = (SID= test) )
(HS=OK)
)';
要注意用户名和密码处需要用双引号,否则Oracle所传输的都是大写字母,可能无法登录进入MysqL。
8,由于MysqL中的表名的大小写敏感,因此需要在进行SQL查询时对表名用双引号扩起来