本文介紹如何在oracle配置mysql數據庫的dblink;雖然dblink使用很佔資源;俗稱「性能殺手」。但有些場景不得不使用它。例如公司使用數據庫是oracle;可能其餘部門或者CP合做公司使用的數據庫是mysql。若須要數據對接。mysql
1. 下載和安裝 [ODBC Driver Manager]
2. 下載和安裝 [MySQL Connector/ODBC driver]
3. 配置odbc.ini
4. 配置環境變量
5. 配置 tnsnames.ora
6. 配置 listener.ora
7. 配置監聽的初始化文件
8. 建立dblinklinux
#建立一個目錄用於放置驅動包環境sql
[oracle@oracle169 ~]$ cd $ORACLE_BASE [oracle@oracle169 app]$ mkdir tools [oracle@oracle169 app]$ cd tools
#下載和安裝 unixODBC-2.2.14-linux-x86-64.tar.gz ;並上傳到tools目錄下。並解壓
#下載地址https://sourceforge.net/projects/unixodbc/files/?source=navbar數據庫
[oracle@oracle169 tools]$ tar -zxvf unixODBC-2.2.14-linux-x86-64.tar.gz [oracle@oracle169 tools]$ mkdir unixodbc-2.2.14 [oracle@oracle169 tools]$ mv usr/local/* unixodbc-2.2.14/ [oracle@oracle169 tools]$ rm -rf usr/
#下載解壓對應版本 mysql-connector-odbc-5.3.7-linux-el6-x86-64bit.tar.gz;本次linux環境是6.5
下載地址 https://dev.mysql.com/downloads/connector/odbc/vim
[oracle@oracle169 tools]$ tar -zxvf mysql-connector-odbc-5.3.7-linux-el6-x86-64bit.tar.gz [oracle@oracle169 tools]$ mv mysql-connector-odbc-5.3.7-linux-el6-x86-64bit my5
[oracle@oracle169 tools]$ vim odbc.ini [testdb] Driver = /u01/app/tools/my5/lib/libmyodbc5a.so SERVER = #mysql服務器ip PORT = #mysql數據庫端口 USER = #mysql數據庫用戶名 PASSWORD = #mysql數據庫密碼 DATABASE = #mysql數據庫 OPTION = 3 SOCKET =
在.bash_profile 後面添加下面bash
export PATH=/u01/app/tools/unixODBC-2.2.14/bin:$PATH export LD_LIBRARY_PATH=/u01/app/tools/unixODBC-2.2.14/lib:$LD_LIBRARY_PATH export ODBCINI=/u01/app/tools/odbc.ini
source .bash_profile以後;這個時候能夠測試上面配置是否正確
執行 isql -v testdb
若出現這個;表示上面配置是OK的。服務器
+---------------------------------------+
| Connected! |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+oracle
在後面添加app
testdb = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SID = testdb)) (HS=OK) ) )
#加入紅色部分;並重啓監聽ide
SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = testdb) (ORACLE_HOME =/u01/app/oracle) (PROGRAM = dg4odbc) (ENVS=LD_LIBRARY_PATH=/u01/app/tools/unixODBC-2.2.14/lib) ) )
[oracle@oracle169 tools]$ vim $ORACLE_HOME/hs/admin/inittestdb.ora # This is a sample agent init file that contains the HS parameters that are # needed for the Database Gateway for ODBC # HS init parameters HS_FDS_CONNECT_INFO = testdb HS_FDS_FETCH_ROWS=100 HS_RPC_FETCH_SIZE=50000 HS_FDS_TRACE_LEVEL = off HS_FDS_SHAREABLE_NAME = /u01/app/tools/unixODBC-2.2.14/lib/libodbc.so HS_LANGUAGE=american_america.we8iso8859p1 HS_NLS_NCHAR=UCS2 # # ODBC specific environment variables # set ODBCINI= /u01/app/tools/odbc.ini # # Environment variables required for the non-Oracle system # #set <envvar>=<value>
create public database link db_testdb connect to "mysql_user" identified by "password" using 'testdb';