linux 操作系统下ORACLE数据库使用透明网关连接MYSQL

在mysql上创建用户
create database dbname;
grant all on dbname.* to username@'%'  identified by ' dbname123';

在oracle服务端安装
 yum install -y mysql-connector-odbc
chown oracle.oinstall /etc/odbc.ini

在oracle服务端配置odbc
vim /etc/odbc.ini
[mysql207]
Description     = MySQL test database
Trace       = debug
TraceFile   = mysql.trace.log
Driver      = /usr/lib64/libmyodbc5.so
SERVER      = 10.100.105.207
USER        = username
PASSWORD    = dbname123
PORT        = 3306
DATABASE    = dbname
-----------
其中,mysql207为服务名,后面将会用到
/usr/lib64/libmyodbc5.so 为odbc 驱动
10.100.105.207 为要访问mysql 所在IP
username登陆mysql 服务器用户名(isql用到,后面创建的dblink不使用)
3306 为mysql 数据库端口(isql用到,后面创建的dblink不使用)


在oracle服务端测试odbc
su - oracle
isql mysql207


在$ORACLE_HOME/hs/admin/目录下,配置initmysql207.ora文件,initmysql207.ora命名方式为init+服务名+.ora。添加如下内容
more $ORACLE_HOME/hs/admin/initmysql207.ora 
# HS init parameters
#
HS_FDS_CONNECT_INFO = mysql207
HS_FDS_TRACE_LEVEL = debug
HS_FDS_SHAREABLE_NAME = /usr/lib64/libmyodbc5.so
#HS_LANGUAGE=AMERICAN_AMERICA.AL32UTF8
HS_LANGUAGE=AMERICAN_AMERICA.UTF8
HS_NLS_NCHAR = UCS2
#HS_LANGUAGE=AMERICAN_AMERICA.WE8ISO8859P1
#HS_FDS_SQLLEN_INTERPRETATION=32
HS_FDS_SQLLEN_INTERPRETATION=64
HS_LONG_PIECE_TRANSFER_SIZE=1258291


# ODBC specific environment variables
#
#set DBCINI=
set DBCINI=/etc/odbc.ini

-------------
HS_FDS_CONNECT_INFO为服务名,与前面保持一致
HS_FDS_TRACE_LEVEL 为日志跟踪级别,不使用时可以设为OFF
HS_FDS_SHAREABLE_NAME 为ODBC驱动
HS_LANGUAGE 为异构服务器的字符集,语言
HS_FDS_SQLLEN_INTERPRETATION 允许64bit 驱动可以使用32bit 标准


修改listener.ora 文件,添加一个监听器:
LISTENER1 =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1522))
    )
  )

SID_LIST_LISTENER1 =
  (SID_LIST =
    (SID_DESC =
      (PROGRAM = dg4odbc)
      (SID_NAME = mysql207)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
    )
  )

或者在oracle增加静态监听:
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (PROGRAM = dg4odbc)
      (SID_NAME = mysql207)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
    )
  )
-----------
SID_NAME为服务名
PROGRAM 为使用dg4odbc 驱动

启动listener1
lsnrctl start listener1

修改tnsnames.ora 文件,添加如下内容
mysql207 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.100.105.207)(PORT = 1522))
    (CONNECT_DATA =
     (SERVICE_NAME = mysql207)
    )
    (hs=ok)
  )

其中SID为前面定义的服务名
HOST为本机的机器名或者IP
PORT为本机的数据库监听器端口

建oracle 中创建数据库链接
sqlplus / as sysdba
create  public database link lnmysql207 connect to "username" identified by " dbname123" using 'mysql207';

测试:
select * from t1@lnmysql207;

RROR at line 1:
ORA-28511: lost RPC connection to heterogeneous remote agent using
SID=ORA-28511: lost RPC connection to heterogeneous remote agent using
SID=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.100.105.208)(PORT=1521))
(CONNECT_DATA=(SID= mysql207)))
ORA-02063: preceding line from LN_MY23_3322
Process ID: 18585
Session ID: 96 Serial number: 207

在init'mysql207.ora文件中添加如下参数
HS_LANGUAGE=AMERICAN_AMERICA.WE8ISO8859P1
#HS_FDS_SQLLEN_INTERPRETATION=32
HS_FDS_SQLLEN_INTERPRETATION=64


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10995764/viewspace-2125628/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10995764/viewspace-2125628/

你可能感兴趣的:(linux 操作系统下ORACLE数据库使用透明网关连接MYSQL)