通过HSODBC访问MySQL的实现步骤

2022-11-12 09:21:19
内容摘要
这篇文章主要为大家详细介绍了通过HSODBC访问MySQL的实现步骤,具有一定的参考价值,可以用来参考一下。 对此感兴趣的朋友,看看idc笔记做的技术笔记!一、环境OS:Linux myhostname
文章正文

这篇文章主要为大家详细介绍了通过HSODBC访问MySQL的实现步骤,具有一定的参考价值,可以用来参考一下。

对此感兴趣的朋友,看看idc笔记做的技术笔记!

一、环境OS:Linux myhostname 2.6.9-42.ELsmp #1 SMP Sat Aug 12 09:39:11 CDT 2006 i686 i686 i386 GNU/LinuxCentOS release 4.4 (Final)Oracle:Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod,数据库已经安装好mysql:5.1.34-community for windows二、安装配置1. 安装unixODBC,用root用户rpm -Uvh unixODBC-2.2.12-1.el4s1.1.i386.rpm2. 安装mysql ODBC,用root用户rpm -Uvh mysql-connector-odbc-5.1.5-0.i386.rpm3. 安装oracle gateway,用oracle用户我装的是10201_gateways_linux32.zipunzip 10201_gateways_linux32.zipcd gateways./runInstaller安装方法和oracle db 软件一样,我把gateway和db装一起了,共用一个OracleHOME4. 配置/etc/odbc.ini[DSName]Driver =/usr/lib/libmyodbc5.soDescription =MySQLServer =xxx.xxx.xxx.xxxPort =3306User =rootUID =rootPassword = mypassDatabase =mysqldbnameOption =3Socket =charset =utf8测试ODBCisql -v DSName root mypass5. 配置$ORACLE_HOME/hs/admin/initDSName.oraHS_FDS_CONNECT_INFO = DSNameHS_FDS_TRACE_LEVEL = 0HS_FDS_SHAREABLE_NAME = /usr/lib/libmyodbc5.so6. 配置listener.ora,加红色部分SID_LIST_LISTENER =(SID_LIST =(SID_DESC =(SID_NAME = PLSExtProc)(ORACLE_HOME = /usr/u01/app/oracle/product/10.2.0/db_1)(PROGRAM = extproc))(SID_DESC =(GLOBAL_DBNAME = BOSS)(ORACLE_HOME = /usr/u01/app/oracle/product/10.2.0/db_1)(SID_NAME = BOSS))(SID_DESC =(SID_NAME = phpcms)(ORACLE_HOME = /usr/u01/app/oracle/product/10.2.0/db_1)(PROGRAM = hsodbc)))7. 配置tnsnames.ora,添加DSName =(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.125)(PORT = 1521)))(CONNECT_DATA = (SERVICE_NAME = DSName))(HS = OK))8. 重启监听器并测试lsnrctl reloadlsnrctl serviceService "DSName" has 1 instance(s).Instance "DSName", status UNKNOWN, has 1 handler(s) for this service...Handler(s):"DEDICATED" established:3 refused:0LOCAL SERVERThe command completed successfullytnsping DSNameAttempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.125)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = DSName)) (HS = OK))OK (0 msec)9. 建立dblinkCREATE PUBLIC DATABASE LINK linknameCONNECT TO "root"IDENTIFIED BY <PWD>USING 'DSName';10. 测试select "name" from t1@linkname;三、遗留问题1. 字符集问题,最好oracle和mysql是utf8,否则中文有问题2. text字段会报错:select "textcol" from t1@linkname;ORA-28500: 连接 ORACLE 到非 Oracle 系统时返回此信息:[Generic Connectivity Using ODBC][MySQL][ODBC 5.1 Driver][mysqld-5.1.34-community]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"t1" WHERE "id"=1' at line 1 (SQL State: 37000; SQL Code: 1064)ORA-02063: 紧接着 2 lines (起自 DSName)本来想用datadirect的mysql ODBC试试,可只支持mysql enterprise版本,实在不好找,以后有机会再说吧。

注:关于通过HSODBC访问MySQL的实现步骤的内容就先介绍到这里,更多相关文章的可以留意

代码注释

作者:喵哥笔记

IDC笔记

学的不仅是技术,更是梦想!