简介
在之前的博客中已经配置过了,可以参考:https://www.xmmup.com/oracle-database-gatewaystoumingwangguandeanzhuanghepeizhi.html#Oracle_lian_jie_daoMySQL
Oracle使用DG4ODBC数据网关连接MySQL数据库,可以不用安装Gateways网关,其原理图如下:
从上图可知,Oracle连接MySQL需要涉及到如下组件:DG4ODBC, ODBC Driver Manager, ODBC Driver。
环境准备
1-- oracle 21c
2docker rm -f ora21tomariadb
3docker run -d --name ora21tomariadb -h lhroracle21c
4 -v /sys/fs/cgroup:/sys/fs/cgroup
5 --privileged=true lhrbest/oracle21c_ee_db_21.3.0.0
6 /usr/sbin/init
7
8-- 由于只读主目录特性,21c中的spfile、pfile、密码文件默认在$ORACLE_BASE/dbs目录下,例如:/u01/app/oracle/dbs下。
9[oracle@lhroracle21c dbs]$ pwd
10/u01/app/oracle/dbs
11[oracle@lhroracle21c dbs]$ ll
12total 18308
13-rw-rw---- 1 oracle oinstall 1544 Mar 18 16:19 hc_LHRCDB.dat
14-rw-r----- 1 oracle oinstall 686 Mar 18 16:19 initLHRCDB.ora
15-rw-r----- 1 oracle oinstall 24 Aug 16 2021 lkLHRCDB
16-rw-r----- 1 oracle oinstall 2048 Aug 16 2021 orapwLHRCDB
17-rw-r----- 1 oracle oinstall 18726912 Aug 16 2021 snapcf_LHRCDB.f
18-rw-r----- 1 oracle oinstall 3584 Mar 18 17:01 spfileLHRCDB.ora
19[oracle@lhroracle21c dbs]$
20
21
22
23
24
25-- mysql 8.1
26mkdir -p /etc/mysql/ora2mysql81/
27cat > /etc/mysql/ora2mysql81/conf/my.cnf use lhrdb;
48Database changed
49mysql> create table t1(id int);
50Query OK, 0 rows affected (0.02 sec)
51
52mysql> insert into t1 values(1);
53Query OK, 1 row affected (0.04 sec)
54
55
56
57
58
59[root@alldb ~]# mysql -uroot -plhr -h192.92.0.54 -P3306 -e "select now(),@@hostname,@@version;"
60mysql: [Warning] Using a password on the command line interface can be insecure.
61+---------------------+-------------+-----------+
62| now() | @@hostname | @@version |
63+---------------------+-------------+-----------+
64| 2024-03-18 16:23:35 | ora2mysql81 | 8.1.0 |
65+---------------------+-------------+-----------+
开始配置
1、以下内容均在Oracle的主机配置。
2、MySQL的主机为192.92.0.54
1-- root操作
2yum install -y unixODBC unixODBC-devel mysql-connector-odbc
3
4-- 升级 mysql-connector-odbc驱动
5rpm -Uvh https://repo.mysql.com//mysql80-community-release-el7.rpm
6yum update -y unixODBC unixODBC-devel mysql-connector-odbc
7
8
9cat >/etc/odbc.ini
51
52
53
54
55
56
57-- oracle操作
58cd /u01/app/oracle/product/21c/dbhome_1/network/admin
59cat >> tnsnames.ora