1, 首先在Oracle所在計算機安裝MySQL的Client端軟件,并且x86_64和i386版本的都需要安裝,以便可以連接MySQL數(shù)據(jù)庫。查看Client安裝情況:
復(fù)制代碼 代碼如下:
rpm -qa |grep mysql
mysql-5.0.45-7.el5
mysql-5.0.45-7.el5
得到兩條記錄,一條是x86_64的,一條是i386的。
如果看到還沒有安裝mysql客戶端軟件,則需要安裝:
復(fù)制代碼 代碼如下:
yum install mysql
yum install mysql.i386
驗證在此Oracle所在計算機是可以連接目標(biāo)主機MySQL數(shù)據(jù)庫:
復(fù)制代碼 代碼如下:
mysql -h 192.168.1.1 -u root -p mysql
2, 檢查Oracle所在計算機是否已安裝MySQL ODBC客戶端,并且x86_64和i386版本的都需要安裝。
復(fù)制代碼 代碼如下:
rpm -qa |grep mysql-connect
如果沒有安裝mysql-connector-odbc,則用下面命令下載和安裝:
下載 mysql-connector-odbc:
復(fù)制代碼 代碼如下:
wget ftp://mirror.switch.ch/pool/3/mirror/centos/5.2/os/i386/CentO S/mysql-connector-odbc-3.51.12-2.2.i386.rpm
安裝mysql-connector-odbc:
復(fù)制代碼 代碼如下:
rpm -ivh mysql-connector-odbc-3.51.12-2.2.i386.rpm
得到提示
復(fù)制代碼 代碼如下:
libltdl.so.3 is needed by mysql-connector-odbc-3.51.12-2.2.i386 ,發(fā)現(xiàn)需要安裝libtool的i386版本,因此通過如下命令安裝libtool-ltdl.i386:
yum list *.i386|grep libtool
yum install libtool-ltdl.i386
3, 在Oracle所在計算機編輯/etc/odbc.ini文件,測試ODBC工作
復(fù)制代碼 代碼如下:
vi /etc/odbc.ini
#odbc.ini內(nèi)容如下
復(fù)制代碼 代碼如下:
[test]
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=
在命令行中執(zhí)行下列命令,應(yīng)能夠順利登入MySQL Client窗口,即證明ODBC功能正常:
復(fù)制代碼 代碼如下:
isql -v test
quit
4, 編輯hs配置文件 vi /ora10g/hs/admin/inittest.ora(注意文件名中藍(lán)色部分為odbc.ini中藍(lán)色名稱)
復(fù)制代碼 代碼如下:
HS_FDS_CONNECT_INFO = test
HS_FDS_TRACE_LEVEL = on(正式使用后,不需要排錯的時候應(yīng)設(shè)為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的監(jiān)聽方式,為將來建立dblink做準(zhǔn)備:
vi /ora10g/network/admin/listener.ora 加入如下語句:
復(fù)制代碼 代碼如下:
(SID_DESC =
(SID_NAME = test)
(ORACLE_HOME = /ora10g)
(PROGRAM = hsodbc)
(ENVS=LD_LIBRARY_PATH=/ora10g/lib32:/usr/lib64:/ora10g/lib)
)
listener.ora文件現(xiàn)在的內(nèi)容變成:
復(fù)制代碼 代碼如下:
SID_LIST_LISTENER = (
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)) )
)
執(zhí)行l(wèi)snrctl reload使Listener生效:
復(fù)制代碼 代碼如下:
su – oracle
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, 2007, 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", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
6, 編輯Oracle所在計算機中的tnsnames.ora文件,便于建立dblink。注意,此tnsnames的配置可以支持tnsping,但是不能支持sqlplus登錄,只用于dblink:
復(fù)制代碼 代碼如下:
vi /ora10g/network/admin/tnsnames.ora
test =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
(CONNECT_DATA =
(SID = test)
)
(HS = OK)
)
7, 在Oracle Database建立dblink:
復(fù)制代碼 代碼如下:
create public database link MYSQL
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所傳輸?shù)亩际谴髮懽帜?,可能無法登錄進(jìn)入MySQL。
8, 由于MySQL中的表名的大小寫敏感,因此需要在進(jìn)行SQL查詢時對表名用雙引號擴起來
復(fù)制代碼 代碼如下:
select * from "tablename"@test
您可能感興趣的文章:- oracle跨庫查詢dblink的用法實例詳解
- Oracle DATABASE LINK(DBLINK)創(chuàng)建與刪除方法
- oracle數(shù)據(jù)庫在客戶端建立dblink語法
- Oracle中建立了dblink怎么使用
- Oracle中dblink的實際應(yīng)用示例詳解