您好,登錄后才能下訂單哦!
這期內容當中小編將會給大家帶來有關oracle如何通過dblink連接mysql實施,文章內容豐富且以專業的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
本周由于公司一個系統的oracle數據庫需要采集另一個系統mysql數據庫的數據,于是對oracle通過dblink連接mysql進行了研究,測試環境是單實例oracle 10g 64位,折騰了半天搞定了,但是生產環境是10g rac,原本以為會很順利,但是折騰了一天多都沒搞定,問題主要出在監聽上面,原本打算放棄,采用中間件連接mysql取數據,但是憑直覺感覺應該是單實例和rac的監聽配置差異造成的,于是在rac節點上單獨創建默認監聽,問題果然解決了。
當配置有問題的時候都會報下面的錯誤:
ORA-28545: error diagnosed by Net8 when connecting to an agent
Unable to retrieve text of NETWORK/NCR message 65535
遇到的主要問題和解決辦法有:
1、oracle 10g 64位的hsodbc應該有問題,文件大小為0,執行hsodbc沒有任何信息;
解決:拷貝32機器下的hsodbc到$ORACLE_HOME/bin目錄下,替換原hsodbc,注意oracle要有權限,下載:http://space.itpub.net/?uid-28321441-action-viewspace-itemid-750733
2、rac監聽不能監聽到hsodbc服務;
解決:netca選擇single node configuration創建監聽來監聽hsodbc服務,監聽端口選擇1522;
3、連接mysql查詢數據亂碼。
解決:編輯/etc/odbc.ini,增加
charset =gbk
STMT =SET NAMES 'GBK'
其中gbk是MYSQL字符集。
具體實施步驟如下:
--oracle服務器:
-- 操作系統:Red Hat Enterprise Linux 5.3
-- 數據庫: Oracle RDBMS 10.2.0.3.0
--mysql服務器:
-- 操作系統:windows server 2003
-- 數據庫: MySQL 5.5
單實例操作如下,操作都在oracle服務器上完成:
--檢查需要的rpm包,需要的包如下,由于hsodbc應該是只支持32位,所以32位包是必須的:
libtool-ltdl-1.5.22-6.1.i386.rpm
libtool-ltdl-1.5.22-6.1.x86_64.rpm
mysql-5.0.77-3.el5.i386.rpm
mysql-5.0.77-3.el5.x86_64.rpm
mysql-connector-odbc-3.51.26r1127-1.el5.i386.rpm
mysql-connector-odbc-3.51.26r1127-1.el5.x86_64.rpm
perl-DBI-1.52-2.el5.x86_64.rpm
unixODBC-2.2.11-7.1.i386.rpm
unixODBC-2.2.11-7.1.x86_64.rpm
上面unixODBC-2.2.11-7.1、mysql-5.0.77-3.el5、mysql-connector-odbc是需要的包,其他是安裝這些包的前提。
安裝完后檢查
# rpm -qa |grep unixODBC
unixODBC-2.2.11-7.1
unixODBC-2.2.11-7.1
# rpm -qa |grep mysql
mysql-5.0.45-7.el5
mysql-5.0.45-7.el5
mysql-connector-odbc-3.51.26r1127-1.el5
mysql-connector-odbc-3.51.26r1127-1.el5
--編輯/etc/odbc.ini
vi /etc/odbc.ini
#[ODBC Data Sources]
#myodbc3 = MySQL ODBC 3.51 Driver DSN
[test]
Driver = /usr/lib/libmyodbc3.so
Description = MySQL ODBC 3.51 Driver DSN
SERVER = 24.1.20.149
PORT = 3306
USER = root
Password = laopo
Database = teng_push
OPTION = 3
SOCKET =
charset =gbk
STMT =SET NAMES 'GBK'
--最后兩個是解決中文亂碼問題,gbk是MYSQL字符集
--切換到oracle用戶
# su - oracle
--編輯環境變量配置文件,主要是LD_LIBRARY_PATH和最后面兩項
$ vi ~/.bash_profile
export ORACLE_BASE=/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export ORACLE_SID=orcl
export ORACLE_TERM=xterm
export PATH=/usr/sbin:$PATH
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"
#export LANG=zh_CN.GB18030
export PATH=.:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$PATH:/bin:/usr/bin:/usr/sbin
:/usr/local/bin:/usr/X11R6/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib32:$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
#ulimit -u 16384 -n 65536
umask 022
export EDITOR=vi
ODBCINI=/etc/odbc.ini; export ODBCINI
ODBCSYSINI=/etc; export ODBCSYSINI
--使配置生效
source ~/.bash_profile
--查看odbc版本及參數文件路徑
$odbcinst -j
unixODBC 2.2.11
DRIVERS............: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
USER DATA SOURCES..: /usr/local/etc/odbc.ini
--測試 My SQL ODBC 驅動
$isql test -v(測試前需要將/etc/odbc.ini中的Driver= /usr/lib/libmyodbc3.so 修改成/usr/lib64/libmyodbc3.so,測試完后還原)
isql test oracle manager -v
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL> quit
--配置 HSODBC 程序
vi $ORACLE_HOME/hs/admin/inittest.ora
HS_FDS_CONNECT_INFO = test
HS_FDS_TRACE_LEVEL = off
HS_FDS_SHAREABLE_NAME=/usr/lib/libmyodbc3.so
set DBCINI=/etc/odbc.ini
--確認 hsodbc 的配置是否正確,如果正確可以看到版本號
--注意:如果是64位oracle,由于hsodbc應該是只支持32位,這里需要拷貝32位機器上的hsodbc到$ORACLE_HOME/bin下替換原有的hsodbc
$ hsodbc
Oracle Corporation --- FRIDAY DEC 06 2012 12:20:44.240
Heterogeneous Agent Release 10.2.0.3.0 - Production Built with
Driver for ODBC
--修改監聽文件,增加下面服務:
(SID_DESC =
(PROGRAM = hsodbc)
(ORACLE_HOME = /oracle/product/10.2.0/db_1)
(SID_NAME = test)
(ENVS=LD_LIBRARY_PATH = /oracle/product/10.2.0/db_1/lib32:/usr/lib:/oracle
/product/10.2.0/db_1/lib)
)
$ vi $ORACLE_HOME/network/admin/listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /oracle/product/10.2.0/db_1)
(PROGRAM = extproc)
)
(SID_DESC =
(PROGRAM = hsodbc)
(ORACLE_HOME = /oracle/product/10.2.0/db_1)
(SID_NAME = test)
(ENVS=LD_LIBRARY_PATH = /oracle/product/10.2.0/db_1/lib32:/usr/lib:/oracle
/product/10.2.0/db_1/lib)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
)
--修改tnsnames.ora
$ vi $ORACLE_HOME/network/admin/tnsnames.ora
test =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =(PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
)
(CONNECT_DATA =
(SID= test)
)
(HS=OK)
)
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
--重啟監聽,要有test服務
$ lsnrctl stop
$ lsnrctl start
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "orcl" has 1 instance(s).
Instance "orcl", 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
--tnsping測試服務
$ tnsping test
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS =(PROTOCOL = TCP)(HOST = 24.1.20.30)(PORT = 1521))) (CONNECT_DATA = (SID= test)) (HS=OK))
OK (0 msec)
--創建dblink
CREATE PUBLIC DATABASE LINK mysql CONNECT TO "root" IDENTIFIED BY "laopo" USING 'test';
--測試
select * from "emp"@mysql where "id"=1;
至此,單節點配置完成。
rac環境下每個節點都需要配置,和單實例唯一的區別是監聽的配置,我試著多種方式去配置監聽,但都沒有監聽到hsodbc的test服務,最后通過netca選擇single node configuration創建監聽來監聽test服務才成功,注意監聽端口改成1522
rac環境節點1的監聽文件如下:
$vi $ORACLE_HOME/network/admin/listener.ora
SID_LIST_LISTENER_RAC01 =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /opt/ora10g/product/10.2.0/db_1)
(PROGRAM = extproc)
)
)
LISTENER_RAC01 =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac01-vip)(PORT = 1521)(IP = FIRST))
(ADDRESS = (PROTOCOL = TCP)(HOST = 24.1.20.246)(PORT = 1521)(IP = FIRST))
)
)
SID_LIST_LISTENER1 =
(SID_LIST =
(SID_DESC =
(PROGRAM=hsodbc)
(ORACLE_HOME=/opt/ora10g/product/10.2.0/db_1)
(SID_NAME=test)
(ENVS=LD_LIBRARY_PATH=/opt/ora10g/product/10.2.0/db_1/lib32:/lib:/usr/lib:
/opt/ora10g/product/10.2.0/db_1/lib)
)
)
LISTENER1 =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 24.1.20.246)(PORT = 1522))
)
)
上述就是小編為大家分享的oracle如何通過dblink連接mysql實施了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。