ORACLE DBLINK MYSQL 的配置方法
前提:
利用SA安装服务器安装的red hat 5.3 的系统,需要再多安装
下列包
zlib-devel-1.2.3-3.x86_64.rpm
libtool-ltdl-1.5.22-6.1.x86_64.rpm
libtool-ltdl-devel-1.5.22-6.1.x86_64.rpm
数据库要安装Gateway选项。
因为使用64 位的unixodbc 以及mysql_connect_odbc RPM 作为安装包,安装成功后,即使oracle 的database link 可以连通mysql ,
但是在使用db link 的时候,到出现数据转换错误,所以要自己手动编译unixodbc 以及mysql-connector-odbc 的source 。
1. 安装mysql client or my server .安装完成后,确认可以连接mysql 数据库。
rpm –ivh MySQL-shared-community-5.1.38-0.rhel5.x86_64.rpm
rpm –ivh MySQL-devel-community-5.1.38-0.rhel5.x86_64.rpm
rpm –ivh MySQL-client-community-5.1.38-0.rhel5.x86_64.rpm
确认:mysql -h IPADDRESS –uuser_name –ppassword offmsg
2. 安装unxiodbc
这个需要手动编译源代码包。首先下载unixODBC-2.2.14-p1.tar.gz ,然后手动编译。
步骤。
gunzip unixODBC-2.2.14-p1.tar.gz
tar –xvf unixODBC-2.2.14-p1.tar
cd unixODBC-2.2.14-p1
export CFLAGS="-DBUILD_REAL_64_BIT_MODE" ---- 用来设定64位环境变量。
# ./configure --enable-gui=no (因没有安装qt 包,所以需要添加--enable-gui=no 参数)
make
make install
3 . 编译mysql-connector-odbc
下载源代码包mysql-connector-odbc-5.1.5r1144.tar.gz
gunzip mysql-connector-odbc-5.1.5r1144.tar.gz
tar –xvf mysql-connector-odbc-5.1.5r1144.tar
cd mysql-connector-odbc-5.1.5r1144
export CFLAGS="-DBUILD_REAL_64_BIT_MODE" ---- 用来设定64位环境变量。
# ./configure --with-mysql-path=/usr/local --enable-gui=no
# make
如果报如下错误
gcc -DHAVE_CONFIG_H -I. -I. -I. -I../util -I.. -DNONTHREADSAFE -I/usr/include -O3 -DDBUG_OFF -I/usr/include/mysql -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -DUNIV_LINUX -DUNIV_LINUX -DBUILD_REAL_64_BIT_MODE -MT libmyodbc5_la-ansi.lo -MD -MP -MF .deps/libmyodbc5_la-ansi.Tpo -c ansi.c -fPIC -DPIC -o .libs/libmyodbc5_la-ansi.o
In file included from driver.h:474,
from ansi.c:28:
myutil.h:206: error: expected declaration specifiers or '...' before 'SQLROWOFFSET'
myutil.h:207: error: expected declaration specifiers or '...' before 'In_C_you_should_use_my_bool_instead'
make[2]: *** [libmyodbc5_la-ansi.lo] Error 1
解决:把报错的文件SQLROWOFFSET 改为 SQLLEN
SQLROWSETSIZE 改为 SQLULEN
bool 改为 my_bool
如果报一下错误:
gcc -shared .libs/libmyodbc5_la-ansi.o .libs/libmyodbc5_la-catalog.o .libs/libmyodbc5_la-connect.o .libs/libmyodbc5_la-cursor.o .libs/libmyodbc5_la-desc.o .libs/libmyodbc5_la-dll.o .libs/libmyodbc5_la-driver.o .libs/libmyodbc5_la-error.o .libs/libmyodbc5_la-execute.o .libs/libmyodbc5_la-handle.o .libs/libmyodbc5_la-info.o .libs/libmyodbc5_la-options.o .libs/libmyodbc5_la-prepare.o .libs/libmyodbc5_la-results.o .libs/libmyodbc5_la-transact.o .libs/libmyodbc5_la-unicode.o .libs/libmyodbc5_la-utility.o -Wl,--whole-archive ../util/.libs/libmyodbc3u.a -Wl,--no-whole-archive -Wl,--rpath -Wl,/usr/lib64/mysql -Wl,--rpath -Wl,/usr/lib64/mysql -L/usr/lib -ldl -L/usr/lib64/mysql /usr/lib64/libltdl.so /usr/lib64/mysql/libmysqlclient_r.so -lcrypt -lnsl -lm -lpthread -lmygcc /usr/lib64/mysql/libz.a -lodbcinst -m64 -Wl,-soname -Wl,libmyodbc5-5.1.5.so -o .libs/libmyodbc5-5.1.5.so
gcc: /usr/lib64/mysql/libmysqlclient_r.so: No such file or directory
make[2]: *** [libmyodbc5.la] Error 1
make[2]: Leaving directory `/tmp/mysql-connector-odbc-5.1.5r1144/driver'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/tmp/mysql-connector-odbc-5.1.5r1144/driver'
make: *** [all-recursive] Error 1
[root@test1 mysql-connector-odbc-5.1.5r1144]#
解决:
cd /usr/lib64/mysql/
ln -s /usr/lib64/libmysqlclient_r.so libmysqlclient_r.so
# make install
4 . 编辑odbc.ini
在unixodbc 的安装目录下(默认为/usr/local) ,进入etc/, 编辑odbc.ini 文件
建立odbc 源。例如:该odbc 源的名称为myodbc3
[odbc151]
Driver = /usr/local/lib/libmyodbc5.so
Description = MySQL
SERVER = 172.18.57.151
PORT = 3306
UID = alisdfim
Password = xk1sdfl9alp73pf
Database = offmsg
OPTION = 3
SOCKET =
#CHARSET = latin1
CHARSET = gbk
5 .配置hs
进入$ORACLE_HOME/hs/admin 目录, 建立initmyodbc3.ora 文件,内容如下:
Initodbc151.ora
#
# HS init parameters
#
HS_FDS_CONNECT_INFO = odbc151
HS_FDS_TRACE_LEVEL = off
HS_FDS_SHAREABLE_NAME = /usr/local/lib/libmyodbc5.so
set ODBCINI=/usr/local/etc/odbc.ini
set LD_LIBRARY_PATH=/usr/local/lib
#HS_LANGUAGE = "ITALIAN_ITALY.WE8MSWIN1252"
#HS_NLS_DATE_FORMAT = "DD/MM/YYYY HH24:MI:SS"
#
# ODBC specific environment variables
#
#
# Environment variables required for the non-Oracle system
6 . 修改监听参数
修改listenter.ora
加入内容
(SID_DESC =
(ORACLE_HOME = /opt/oracle/products/11.1.0/db_1)
(SID_NAME = odbc151)
(PROGRAM = dg4odbc)
(ENVS ="LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/opt/oracle/products/11.1.0/db_1/lib")
)
然后 重新启动 listener . 执行lsnrctl status ,可以看到已经添加新的instance odbc151
7. 添加tns name .
向tnsnames.ora 添加
MYtest =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)
(HOST = 172.18.112.192)
(PORT = 1521)
)
)
(CONNECT_DATA =
(SERVICE_NAME = odbc151)
)
(HS = OK)
)
执行tnsping mytest , 确认是否可以tnsping 通。
8. 登录本机的oracle 数据库, 创建database link
Create database link ora_to_mysql connect to “cactiuser” identified by “cactiuser” using ‘mytest’;
测试database Link 是否可以使用。能使用,表示安装配置成功。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22795861/viewspace-1028327/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/22795861/viewspace-1028327/