oracle通过dblink连接mysql配置详解(全Windows下)
关于oracle通过dblink连接mysql,经过了两周的空闲时间研究学习,终于配置好了,真是不容易啊,仔细想想的话,其实也没花多长时间,就是刚开始走了一段弯路,所以把这次的经验分享出来,让大家少走些弯路,OK,闲话不多说了,开始配置旅程:
一:环境检查:
数据库:安装oracle11g 64位,安装mysql 5.6 64位,Windows7系统;
安装数据源驱动(ODBC) 64位,Windows7系统;
数据源下载地址:http://pan.baidu.com/s/1dFeGUDr;
接下来需要检查的是否安装了oracle透明网关,如下图所示:
二:检查之后没问题开始安装:
(1)在开始菜单中搜索ODBC:
打开后选择系统DSN:
选择第一个就可以了
配置完成后点击完成就可以了,这样Mysql的ODBC就已经有了
(2)接下来进行oracle透明网关配置:
找到你的oracle的安装目录的initdg4odbc.ora文件(我安装在E盘):
E:\app\Administrator\product\11.2.0\dbhome_1\hs\admin(这是我
安装在E盘下面),然后复制一份,命名规则是:init+sid.ora,所以就是initmysqlodbc.ora;
然后打开initmysqlodbc.ora文件,添加如下内容:
HS_FDS_CONNECT_INFO = mysqlodbc 说明:和mysql的odbc保持一致
HS_FDS_TRACE_LEVEL = off 说明:需要调试时可以改为debug,调试完成改为off;
然后打开E:\app\Administrator\product\11.2.0\dbhome_1\NETWORK\ADMIN 的listener.ora文件:
# listener.ora Network Configuration File: E:\app\Administrator\product\11.2.0\dbhome_1\NETWORK\ADMIN\listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = E:\app\Administrator\product\11.2.0\dbhome_1)
(PROGRAM = extproc)
(ENVS = "EXTPROC_DLLS=ONLY:E:\app\Administrator\product\11.2.0\dbhome_1\bin\oraclr11.dll")
)
***(SID_DESC =
(SID_NAME = MYSQLODBC)
(ORACLE_HOME = E:\app\Administrator\product\11.2.0\dbhome_1)
(PROGRAM = dg4odbc)
)***
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
)
ADR_BASE_LISTENER = E:\app\Administrator
带星号字体为配置部分;。。。!!!粘贴时要注意,括号上和上边下边的对齐,否则启动监听报错。。。!!!
然后重启监服务,可以在service.msc里重启,也可以使用命令lsnrctl stop ,lsnrctl start;
接下来打开tnsnames.ora(跟监听配置文件在同一个目录下)
# tnsnames.ora Network Configuration File: E:\app\Administrator\product\11.2.0\dbhome_1\NETWORK\ADMIN\tnsnames.ora
# Generated by Oracle configuration tools.
LISTENER_ORCL =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
ORACLR_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
(CONNECT_DATA =
(SID = CLRExtProc)
(PRESENTATION = RO)
)
)
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
**MYSQLODBC =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = mysqlodbc)
)
(HS = OK)
)**
带星号字体为新添加的配置(mysqlodbc),保存;
最后用oracle连接工具创建dblink:
create database link mysqlodbc connect to "root" identified by "123456" using 'mysqlodbc';--注意使用单引号
测试一下是否能够连接,提示连接成功说明能够访问mysql;
为了进一步验证,我这里还做了新增数据的测试(不要忘记点击提交按钮,不然在mysql客户端无法查到数据):
然后再次查询,能查得到:
接着我再到mysql去查询,也能查到:
到这里已经将所有的配置完成。
<link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/production/markdown_views-ea0013b516.css">
</div>