当前位置: 代码迷 >> 综合 >> Oracle 连接mysql dblink 透明网关配置测试
  详细解决方案

Oracle 连接mysql dblink 透明网关配置测试

热度:86   发布时间:2023-12-20 12:21:32.0

环境:

源端

10.100.55.xx  oracle

目标端:

10.100.40.xxx mysql

 

具体步骤:

--源端安装mysql-connector-odbc

[root@oracle tmp]# rpm -ivh mysql-connector-odbc-5.1.13-1.rhel5.x86_64.rpm
Preparing...                ########################################### [100%]
   1:mysql-connector-odbc   ########################################### [100%]
Success: Usage count is 1
[root@oracle tmp]# 


--目标端创建连接用户
grant select on test.* to oratest@'%'  identified by 'ora123';

 


--源端配置 /etc/odbc.ini文件,添加如下内容

[mysqltest]

Driver   = /usr/lib64/libmyodbc5.so

Server   = 10.100.40.xxx

User = oratest

Password = ora123

Port = 3306

database = test

 

#mysqltest 为服务名,后面将会用到

#/usr/lib64/libmyodbc5.so 为odbc 驱动

#10.100.40.xxx 为要访问mysql 目标端所在IP

#oratest 登陆mysql 服务器用户名

#3306 为mysql 数据库端口

 

--在源端使用isql 命令进行测试

isql mysqltest

[root@oracle etc]# isql mysqltest
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL> quit   

能够连接上表示ODBC配置成功


--源端在$ORACLE_HOME/hs/admin目录下,配置initmysqltest.ora文件,   initmysqltest.ora命名方式为init+服务名+.ora

vi initmysqltest.ora

# HS init parameters
HS_FDS_CONNECT_INFO=mysqltest
# Data source name in odbc.ini
HS_FDS_TRACE_LEVEL= 255
HS_FDS_SHAREABLE_NAME=/usr/lib64/libmyodbc5.so
HS_FDS_SUPPORT_STATISTICS=FALSE
HS_KEEP_REMOTE_COLUMN_SIZE=ALL
HS_LANGUAGE=AMERICAN_AMERICA.AL32UTF8

HS_NLS_NCHAR=UCS2
HS_FDS_SQLLEN_INTERPRETATION=32
HS_IDLE_TIMEOUT = 1440
#
# ODBC env variables
set ODBCINI=/etc/odbc.ini

--源端新建监听

vi listener.ora

LISTENER_mysql =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = oracle )(PORT = 1523))
  )
  
SID_LIST_LISTENER_mysql =
   (SID_DESC =
        (SID_NAME = mysqltest)
        (ORACLE_HOME = /oracle/ora11g/product/11.2.0/db_1)
        (PROGRAM = dg4odbc)
        (ENVS=LD_LIBRARY_PATH=/usr/lib64:/usr/lib:/oracle/ora11g/product/11.2.0/db_1/lib:/oracle/ora11g/product/11.2.0/db_1/odbc/lib)
   )
 

--源端增加tns
vi tnsnames.ora

mysqltest =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = oracle)(PORT = 1523))
    )
    (CONNECT_DATA =
      (SID = mysqltest)
    )
   (HS = OK)
  )
  
  

--源端oracle数据库中建立dblink
create  database link to_mysql 
connect to "oratest" identified by "ora123" using 'mysqltest';

--测试
select count(1) from t_test@to_mysql;

select * from dual@to_mysql;

如正常返回结果,则连通性正常。

  相关解决方案