Oracle access MySql via unixODBC by DBLINK
Oracle access MySql via unixODBC by DBLINK原来公司的同事询问了一个问题:我问一下oracle连接远程mysql的方法 我之前用hsodbc 但是不能显示不同属性的字段oracle好像也没for mysql的透明网关 请问有什么方法能远程获取mysql的数据? 我oracle专门做分析的 会调用mysql的数据 所以就要获取mysql的数据 又不想做同步------------、介个你懂吗对MySql了解仅限于通用的SQL语句,其他完全不懂;但是我知道至少有超过2中以上的办法来实现这个需求。他这里应该是借助unixODBC来访问MySql的数据,以下是测试过程。环境:MySql5.6 For Windows2003Oracle10G For CentOS5.70. MySql安装部署数据准备MySql在windows2003上的安装部署非常简单,简单的一步一步next就好了,这里略过,我们将创建一个数据库用户gtlions,创建一个表access_by_oracle并插入几条测试数据。C:\Documents and Settings\Administrator>mysql -u root -pEnter password: ******Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.6.10-log MySQL Community Server (GPL)Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> helpFor information about MySQL products and services, visit:http://www.mysql.com/For developer information, including the MySQL Reference Manual, visit:http://dev.mysql.com/To buy MySQL Enterprise support, training, or other products, visit:https://shop.mysql.com/List of all MySQL commands:Note that all text commands must be first on line and end with ';'? (\?) Synonym for `help'.clear (\c) Clear the current input statement.connect (\r) Reconnect to the server. Optional arguments are db and host.delimiter (\d) Set statement delimiter.ego (\G) Send command to mysql server, display result vertically.exit (\q) Exit mysql. Same as quit.go (\g) Send command to mysql server.help (\h) Display this help.notee (\t) Don't write into outfile.print (\p) Print current command.prompt (\R) Change your mysql prompt.quit (\q) Quit mysql.rehash (\#) Rebuild completion hash.source (\.) Execute an SQL script file. Takes a file name as an argument.status (\s) Get status information from the server.tee (\T) Set outfile [to_outfile]. Append everything into given outfile.use (\u) Use another database. Takes database name as argument.charset (\C) Switch to another charset. Might be needed for processing binlogwith multi-byte charsets.warnings (\W) Show warnings after every statement.nowarning (\w) Don't show warnings after every statement.For server side help, type 'help contents'mysql> CREATE USER 'gtlions'@'%' IDENTIFIED BY '000000';ERROR 1396 (HY000): Operation CREATE USER failed for 'gtlions'@'%'mysql> CREATE USER 'gtlions' IDENTIFIED BY '000000';Query OK, 0 rows affected (0.00 sec)mysql> GRANT USAGE ON * . * TO 'gtlions' IDENTIFIED BY '000000' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;Query OK, 0 rows affected (0.00 sec)mysql> CREATE DATABASE IF NOT EXISTS `gtlions` ;Query OK, 1 row affected (0.00 sec)mysql> GRANT ALL PRIVILEGES ON `gtlions` . * TO 'gtlions';Query OK, 0 rows affected (0.00 sec)mysql>exitByeC:\Documents and Settings\Administrator>mysql -u gtlions -pEnter password: ******Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 22Server version: 5.6.10-log MySQL Community Server (GPL)Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> use gtlionsDatabase changedmysql> create table access_by_oracle(id int(5),name char(20));Query OK, 0 rows affected (0.09 sec)mysql> insert into access_by_oracle values(1,'gtlions');Query OK, 1 row affected (0.00 sec)mysql> insert into access_by_oracle values(2,'laidye');Query OK, 1 row affected (0.00 sec)mysql> select * from access_by_oracle;+------+---------+| id | name |+------+---------+| 1 | gtlions || 2 | laidye |+------+---------+2 rows in set (0.00 sec)mysql>好了,MySql已经安装部署完毕并准备可以对外访问了。1. Oracle访问端配置我们需要借助unixODBC来访问,如果系统有自带安装好的就可以直接使用,如果没有就要安装它,可以使用yum或者源码包的方式,由于我这里系统已经安装好了,不再描述,如果需要yum安装它,命令参考如下:yum -y unixODBC我本机上已经安装完成的如下包:[root@gtserdev ~]# rpm -qa|grep unixODBCunixODBC-devel-2.2.11-10.el5unixODBC-libs-2.2.11-10.el5unixODBC-2.2.11-10.el5unixODBC-kde-2.2.11-10.el5安装完成后编辑/etc/odbc.ini,内容如下:[oracle@gtserdev admin]$ cat /etc/odbc.ini[test]Driver=/usr/lib/libmyodbc3_r.soDescription=MySQLServer=192.168.56.101Port=3306User=gtlionsPassword=000000Database=gtlionsOption=3Socket=上述内容第3行开始为MySql服务器地址、端口、用户、密码、数据库,酌情修改吧。然后执行下列命令进行测试,如果能够顺利登入MySQL Client窗口,说明我们的unixODBC功能可以正常:[root@gtserdev ~]# isql -v test+---------------------------------------+| Connected! || || sql-statement || help [上一个:oracle的scott用户下默认表
下一个:Oracle/Sql高级篇
- 更多Oracle疑问解答:
- 运行exp备份oracle数据库提示oracle-12154错误
- 有没有,生产Oracle Rman 备份脚本的工具啊!
- 初学orcle,希望有大大帮忙解说一下详细步骤,从登录oracle到创建表的过程
- oracle语句问题:一张user表,三个字段,id,name,time,插入记录比如:张三2007,李四2008,张三2011
- 如何写一个ORACLE触发器同步两个表中的数据?
- oracle 如何查看一个服务器上有多少个数据库.
- oracle 创建包的时候错误 求解
- oracle 重复列的问题
- oracle 中如何查处2星期前的数据
- 请教oracle数据库安装中的问题
- 请问谁能提供给我标准的oracle ERP的数据库表结构并详细说明各表主要的作用?
- 安装oracle遇到的问题 invalid entry CRC (expected 0x3e12e795 but got 0x9db0e9fd)
- 我的是ORACLE 10G,在RMAN中如何按指定的时间恢复数据文件啊?
- oracle为什么没有自动增长列
- oracle快捷键都有哪些啊?