MySQL服务器信息:
IP: 172.17.10.71
数据库版本:MySQL 5.7
操作系统:Oracle Linux 6.5
Oracle服务器信息:
IP:172.17.10.179
数据库版本:Oracle 11.2.0.4
操作系统:Oracle Linux 6.5
注:除了创建连接用的用户名外,其它操作均在Oracle服务器上操作
[root@Ora ~]# rpm -ivh mysql-connector-odbc-8.0.16-1.el6.x86_64.rpm
warning: mysql-connector-odbc-8.0.16-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
libodbc.so.2()(64bit) is needed by mysql-connector-odbc-8.0.16-1.el6.x86_64
libodbcinst.so.2()(64bit) is needed by mysql-connector-odbc-8.0.16-1.el6.x86_64
提示需要安装依赖包,根据提示安装依赖包
在此给大家介绍个rpm包下载站,这个下载站可根据你检索的内容检索出你需要的安装包
例如:根据上面提示我需要libodbc.so.2,我就检索libodbc.so.2
得到的结果就是安装unixODBC这个包
同样,检索libodbcinst.so.2
得到结果也是安装unixODBC这个包
那么我安装这个表即可解决上述的依赖问题
[root@Ora ~]# yum install unixODBC -y
再次安装rpm包
[root@Ora ~]# rpm -ivh mysql-connector-odbc-8.0.16-1.el6.x86_64.rpm
warning: mysql-connector-odbc-8.0.16-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-connector-odbc ########################################### [100%]
Success: Usage count is 1
Success: Usage count is 1
成功安装
[oracle@Ora ~]$ dg4odbc
Oracle Corporation --- MONDAY JUN 10 2019 15:27:03.146
Heterogeneous Agent Release 11.2.0.4.0 - 64bit Production Built with
Oracle Database Gateway for ODBC
mysql> create user 'test'@'%' identified by 'Test#123';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on *.* to test;
Query OK, 0 rows affected (0.02 sec)
编辑ODBC配置文件:
[root@Ora ~]# vim /etc/odbc.ini
-------依照如下内容填写配置----------
[mysqltest]
Driver =/usr/lib64/libmyodbc8w.so
Server =172.17.10.71
Port =3306
User =test
Password=Test#123
Database=hr
-----------------------------------
Driver:驱动的路径
Server:服务器地址
Port:端口号
Password:密码
Database:要访问的数据库
这个版本下有两个驱动,分别是myodbc8w和myodbc8a,其区别如下:
该配置文件可参考官方文档:https://dev.mysql.com/doc/connector-odbc/en/connector-odbc-configuration-dsn-unix.html
测试连通性:
[root@Ora ~]# isql mysqltest
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL> quit
配置成功
[oracle@Ora ~]$ cd $ORACLE_HOME/hs/admin
[oracle@Ora admin]$ cat initmysqltest.ora
#HS
HS_FDS_CONNECT_INFO = mysqltest
HS_FDS_SHAREABLE_NAME = /usr/lib64/libodbc.so
HS_LANGUAGE = AMERICAN_AMERICA.ZHS16GBK
#ODBC
set ODBCINI=/etc/odbc.ini
HS_FDS_CONNECT_INFO:
HS_FDS_SHAREABLE_NAME:
HS_LANGUAGE:
官方文档参考:https://docs.oracle.com/cd/E11882_01/gateways.112/e12061/apd.htm#OTGIW1120
增加对应的监听配置:
Oracle 的 listener.ora文件,静态监听配置段,增加如下内容(红框标记):
重载监听
[oracle@Ora admin]$ lsnrctl reload
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 10-JUN-2019 16:40:58
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
The command completed successfully
配置Oracle 的 tnsnames.ora 文件
新增加如下配置段(红框标注部分):
测试连通性:
[oracle@Ora admin]$ tnsping mysql
TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 10-JUN-2019 16:47:09
Copyright (c) 1997, 2013, Oracle. All rights reserved.
Used parameter files:
/oracle/product/11.2.0/db_1/network/admin/sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.17.10.179)(PORT = 1521)) (CONNECT_DATA = (SID = mysqltest)) (HS = OK))
OK (10 msec)
SYS@oratest> create public database link LNK_MYSQL connect to "test" identified by "Test#123" using 'MYSQL';
Database link created.
--测试
SYS@oratest> select "employee_id" from "employees"@LNK_MYSQL;
employee_id
-----------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
19 rows selected.
注意:在MySQL库中,表名、列名区分大小写,在Oracle端进行查询时要使用双引号区分大小写
https://www.cnblogs.com/rangle/p/8967643.html
http://blog.itpub.net/12679300/viewspace-1177222/
https://www.cndba.cn/jane/article/1833
以及 Oracle、MySQL官方文档