oracle 透明网关,oracle到mysql的dblink

总体思路

oracle——>dg4odbc——>odbc——>mysql

1、查看DG4ODBC版本

[oracle@node1 ~]$ file $ORACLE_HOME/bin/dg4odbc

/tmp/soft/app/oracle/product/112040/dbhome_1/bin/dg4odbc: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped

2.下载并安装64位的ODBC Driver Manager UnixODBC

下载地址:
请参看官方文档 Detailed Overview of Connecting Oracle to MySQL Using DG4ODBC Database Link (文档 ID 1320645.1)

www.unixodbc.org
下载最新版本
在这里插入图片描述

安装
介质上传/tmp
root赋权:
[root@ljw tmp]# chmod 777 *
[root@ljw tmp]# ls -rtl
total 12756
-rwxrwxrwx 1 root root 1830660 Jul 1 00:21 unixODBC-2.3.4.tar.gz

oracle解压:
解压unixODBC
tar -zxvf unixODBC-2.3.4.tar.gz

root安装:
[root@ljw /]# mkdir -p /usr/local/unixODBC
[root@ljw /]# cd /tmp/unixODBC-2.3.4
[root@ljw unixODBC-2.3.4]# ./configure --prefix=/usr/local/unixODBC
[root@ljw unixODBC-2.3.4]# make & make install

测试:
[root@node1 etc]# odbcinst -j
在这里插入图片描述

3.下载并安装ODBC Driver

http://dev.mysql.com/downloads/connector/odbc/#downloads

安装
rpm -ivh mysql-connector-odbc-8.0.33-1.el6.x86_64.rpm

4.配置:

vi /etc/odbc.ini
[mysql]
Description = mysql
Driver = MySQL ODBC 8.0 Unicode Driver
Server = ** //MySQL服务器IP
Database = yqt_if //MySQL数据库名 (对大小写敏感)
Port = 3306 //端口
USER = root //数据库用户名
Password = root //用户名密码
Socket =
Option = 3
Stmt =
CHARSET = UTF8 //数据库字符集
在这里插入图片描述

driver的内容见同路径下的odbcinst.ini
在这里插入图片描述

验证:
isql mysql -v
在这里插入图片描述

5. 在.bash_profile配置相关环节变量

[oracle@ljw etc]$ vi ~/.bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

umask 022
export ORACLE_BASE=/oracle/app
export ORACLE_HOME=/oracle/app/product/11.2.0/db_1
export ORACLE_SID=orcl
export PATH=$ORACLE_HOME/bin:$PATH

6.配置监听

添加静态监听
vi listener.ora

LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.83.50)(PORT = 1521))
)

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC=
(SID_NAME=myodbc5)
(ORACLE_HOME=/tmp/soft/app/oracle/product/112040/dbhome_1)
(PROGRAM=dg4odbc)
)
)

7.配置tns

vi tnsnames.ora

myodbc5 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.83.50 )(PORT = 1521))
(CONNECT_DATA =
(SID=myodbc5)
)
(HS=OK)
)

8.配置odbc

cd $ORACLE_HOME/hs/admin

vi initmyodbc5.ora

HS_FDS_CONNECT_INFO=mysql
HS_FDS_SHAREABLE_NAME=/usr/lib64/libodbc.so
HS_FDS_SUPPORT_STATISTICS= FALSE
HS_LANGUAGE=AMERICAN_AMERICA.UTF8
HS_NLS_NCHAR=UCS2
set ODBCINI=/etc/odbc.ini

9.监听重启

lsnrctl reload

10.创建dblink

create public database link new_e connect to “kaka” identified by “oracle” using ‘myodbc5’;

select * from gaga@new_e;