首页 > 数据库 >oracle使用dblink连接mysql

oracle使用dblink连接mysql

时间:2023-10-21 22:03:36浏览次数:44  
标签:stu12c ... odbc dblink usr mysql oracle

在oracle数据库访问mysql数据库数据

环境

Oracle  数据库: 192.168.22.6 端口1521 操作系统:RHEL 7.6
MYSQL 数据库: 192.168.22.9 端口3306 操作系统:RHEL 7.6  用户:lanmc,密码:lanmc123 ,数据库 lanmc

ORACLE 数据库配置

  • 1、oracle服务端安装mysql odbc
mysql odbc下载地址:https://dev.mysql.com/downloads/connector/odbc/

rpm -ivh mysql-connector-odbc-8.0.31-1.el7.x86_64.rpm 
warning: mysql-connector-odbc-8.0.31-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-connector-odbc-8.0.31-1.el7################################# [100%]

[root@t12c ~]# rpm -ql mysql-connector-odbc-8.0.31-1.el7.x86_64
/usr/bin/myodbc-installer
/usr/lib64/libmyodbc8a.so
/usr/lib64/libmyodbc8w.so
/usr/share/doc/mysql-connector-odbc-8.0.31
/usr/share/doc/mysql-connector-odbc-8.0.31/ChangeLog
/usr/share/doc/mysql-connector-odbc-8.0.31/INFO_BIN
/usr/share/doc/mysql-connector-odbc-8.0.31/INFO_SRC
/usr/share/doc/mysql-connector-odbc-8.0.31/LICENSE.txt
/usr/share/doc/mysql-connector-odbc-8.0.31/README.txt
  • 2、安装最新的unixODBC
下载地址:http://www.unixodbc.org/

1. copy the unixODBC-2.3.11.tar.gz file somewhere you can create files and directories
2. gunzip unixODBC*.tar.gz
3. tar xvf unixODBC*.tar

./configure              ## 指定路径安装 ./configure --prefix=/usr/local/unixODBC
make
make install


[root@t12c ~]# odbcinst -j
unixODBC 2.3.11
DRIVERS............: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8

检查路径是否为配置文件路径;如不是

1.直接在 /usr/local/etc/ 目录下配置odbcinst.ini 和 odbc.ini.
2.在其他目录配置,之后使用odbcinst 命令加载2个配置。
odbcinst -i -d -f /etc/odbc.ini
odbcinst -i -s -l -f /etc/odbc.ini
  • 3、在/etc目录下创建odbc.ini文件
[root@t12c ~]# vi /etc/odbc.ini
[MYSQL]
Driver       = /usr/lib64/libmyodbc8w.so            ## mysql odbc的lib
Description  = Connector ODBC 8
SERVER       = 192.168.22.9
PORT         = 3306
USER         = lanmc
Password     = lanmc123
Database     = lanmc
OPTION       = 0
TRACE        = OFF
CHARSET      = UTF8

## 测试连接
[root@t12c ~]# isql MYSQL
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL> select * from t1;
+-----------+-----------+
| id1       | id2       |
+-----------+-----------+
| 3333      | 6412      |
+-----------+-----------+
SQLRowCount returns 1
1 rows fetched
SQL> quit()
  • 4、配置透明网关
[oracle@t12c admin]$ vi initMYSQL.ora 
HS_FDS_CONNECT_INFO = MYSQL
HS_FDS_TRACE_LEVEL = OFF
HS_FDS_SHAREABLE_NAME = /usr/lib64/libodbc.so           ## 该参数值应该为unixodbc的lib包,如果配置为mysql odbc的lib包,查询时会报错ORA-28500
HS_NLS_NCHAR = UCS2
HS_LANGUAGE=AMERICAN_AMERICA.AL32UTF8    ## 两边数据库的字符集都为utf8
set ODBCINI=/etc/odbc.ini
#HS_LANGUAGE = AMERICAN_AMERICA.WE8ISO8859P15
set LD_LIBRARY_PATH=/usr/lib64/
  • 5、编辑监听文件
[oracle@t12c admin]$ vi listener.ora 
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
        (GLOBAL_DBNAME =STU_DGMGRL)
        (ORACLE_HOME = /oracle/app/product/12.2.0/db)
        (SID_NAME =stu12c)
    )
    (SID_DESC =
        (GLOBAL_DBNAME =stu12c)
        (ORACLE_HOME = /oracle/app/product/12.2.0/db)
        (SID_NAME =stu12c)
    )
    (SID_DESC =
        (SID_NAME =MYSQL)
        (ORACLE_HOME = /oracle/app/product/12.2.0/db)
      (PROGRAM=dg4odbc)
      (ENVS=LD_LIBRARY_PATH="/usr/lib64: /oracle/app/product/12.2.0/db/lib")
    )
)
  • 6、编辑$ORACLE_HOME/network/admin/tnsnames.ora
[oracle@t12c admin]$ vi tnsnames.ora 

MYSQL =
 (DESCRIPTION =
  (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.22.6)(PORT = 1521))
  (CONNECT_DATA =
  (SID = MYSQL)
  )
 (HS = OK)
 )

[oracle@t12c admin]$ lsnrctl reload

LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 20-DEC-2022 19:55:19

Copyright (c) 1991, 2016, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.22.6)(PORT=1521)))
The command completed successfully
[oracle@t12c admin]$ lsnrctl status

LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 20-DEC-2022 19:55:23

Copyright (c) 1991, 2016, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.22.6)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date                20-DEC-2022 16:13:28
Uptime                    0 days 3 hr. 41 min. 54 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /oracle/app/product/12.2.0/db/network/admin/listener.ora
Listener Log File         /oracle/app/diag/tnslsnr/t12c/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.22.6)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "MYSQL" has 1 instance(s).
  Instance "MYSQL", status UNKNOWN, has 1 handler(s) for this service...
Service "PG" has 1 instance(s).
  Instance "PG", status UNKNOWN, has 1 handler(s) for this service...
Service "STU_DGMGRL" has 1 instance(s).
  Instance "stu12c", status UNKNOWN, has 1 handler(s) for this service...
Service "destdb" has 1 instance(s).
  Instance "stu12c", status READY, has 1 handler(s) for this service...
Service "df66fa250c1347e7e0530616a8c0b8a4" has 1 instance(s).
  Instance "stu12c", status READY, has 1 handler(s) for this service...
Service "e7fa5abedc356516e0530616a8c06294" has 1 instance(s).
  Instance "stu12c", status READY, has 1 handler(s) for this service...
Service "stat_test" has 1 instance(s).
  Instance "stu12c", status READY, has 1 handler(s) for this service...
Service "stu12c" has 2 instance(s).
  Instance "stu12c", status UNKNOWN, has 1 handler(s) for this service...
  Instance "stu12c", status READY, has 1 handler(s) for this service...
Service "stu12cXDB" has 1 instance(s).
  Instance "stu12c", status READY, has 1 handler(s) for this service...
Service "stu12c_CFG" has 1 instance(s).
  Instance "stu12c", status READY, has 1 handler(s) for this service...
Service "stu12c_DGB" has 1 instance(s).
  Instance "stu12c", status READY, has 1 handler(s) for this service...
The command completed successfully


[oracle@t12c admin]$ tnsping MYSQL

TNS Ping Utility for Linux: Version 12.2.0.1.0 - Production on 20-DEC-2022 19:55:45

Copyright (c) 1997, 2016, Oracle.  All rights reserved.

Used parameter files:
/oracle/app/product/12.2.0/db/network/admin/sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.22.6)(PORT = 1521)) (CONNECT_DATA = (SID = MYSQL)) (HS = OK))
OK (0 msec)


SQL> create public database link mysql_link connect to "lanmc" identified by "lanmc123" using 'mysql';

Database link created.


SQL> select * from "t1"@mysql;

       id1        id2
---------- ----------
      3333       6412

标签:stu12c,...,odbc,dblink,usr,mysql,oracle
From: https://blog.51cto.com/u_13482808/7969742

相关文章

  • Mysql死亡笔记的死锁记录
    死锁记录线上MySQL死锁了,我赶紧登录线上系统,查看业务日志。能清楚看到是这条insert语句发生了死锁。MySQL如果检测到两个事务发生了死锁,会回滚其中一个事务,让另一个事务执行成功。很明显,我们这条insert语句被回滚了。insertintouser(id,name,age)values(6,'张三',6);但是......
  • 什么是MySQL索引下推优化
    索引条件下推优化(IndexConditionPushdown(ICP))是MySQL5.6添加的,用于优化数据查询。不使用索引条件下推优化时存储引擎通过索引检索到数据,然后返回给MySQLServer,MySQLServer进行过滤条件的判断。当使用索引条件下推优化时,如果存在某些被索引的列的判断条件时,MySQLServer将......
  • php js + laravel + mysql开发的手术麻醉临床信息系统源码
    手术麻醉临床信息系统有着完善的临床业务功能,能够涵盖整个围术期的工作,能够采集、汇总、存储、处理、展现所有的临床诊疗资料。通过该系统的实施,能够规范麻醉科的工作流程,实现麻醉手术过程的信息数字化,自动生成麻醉的各种医疗文书,完成共享HIS、LIS、PACS和EMR等手术患者信息,从而提......
  • Mysql一文流
    一文读懂MySQL数据库1.MySQL简介1.1数据库介绍​数据库(Database,DB)从本质上讲就是一个文件系统,它能够讲数据有组织地集合砸一起,按照一定的规则长期存储到计算机的磁盘中,并且能够供多个用户共享和使用,同时,用户能够对数据库中的数据进行插入、删除、修改和查询操作​......
  • Oracle数据编纂(脱敏)
    OracleDatabase-EnterpriseEdition-Version12.1.0.2andlater1.问题描述客户需求:Oracle数据库里面能不能实现这么一个功能,让符合条件的用户可以看到表里面的所有数据,而另外一些人(比如权限低的用户)虽然能查询表,但是对某些敏感数据全部用星号加密了。效果如下图所示:=>2.问题......
  • Oracle获取执行计划的七种方法以及使用场景
    一.explainplanforselect*fromt1,t2 wheret1.id=t2.id andt1.idin(5,6);select*fromtable(dbms_xplan.display());优点无需真正执行,快捷方便缺点1.没有输出运行时的相关统计信息(产生多少逻辑读,多少次物理读,多少次递归调用等);2.无法判断是处理了多少行;3.无法判断表被......
  • MySql安装与使用
    mysql是目前最流行的关系型数据库管理系统,在WEB应用方面MySQL是最好的RDBMS(RelationalDatabaseManagementSystem:关系数据库管理系统)应用软件之一。MySQL是非常灵活的一款数据库,虽然它不是绝对完美,但它的灵活足够适应很多高要求的环境。为了发挥MySQL的性能并很好的使用它,我......
  • MySQL常用函数
    MySQL函数,是一种控制流程函数,属于数据库用语言。MySQL数据库中提供了很丰富的函数。MySQL函数包括数学函数、字符串函数、日期和时间函数、条件判断函数、系统信息函数、加密函数、格式化函数等。通过这些函数,可以简化用户的操作。一、数学函数1.1、函数概述MySQL函数是MySQL......
  • MySQL多主模型实战
    MySQLAB解决了数据备份的问题,但是当A由于某些原因宕机后,WEB服务器就没有办法在往数据库写或者读写了。线上业务中断了,完了,出事故了。这该怎么办呢?本节课主要给大家讲解如果处理因为MySQL主服务器宕机造成的业务中断问题,保障MySQL业务高可用。一、实验拓扑图二、架构原理1、M......
  • MySQL子查询
    在SQL语言中,一个SELECT-FROM-WHERE语句称为一个查询块。当获得一个查询的答案需要多个步骤的操作,首先必须创建一个查询来确定用户不知道但包含在数据库中的值,将一个查询块嵌套在另一个查询块的WHERE字句或HAVING短语的条件中查询块称为子查询或内层查询。上层的查询块曾为父查询或......