Linux 下安装 Oracle 客户端

  1. 使用 ZIP文件离线安装 Oracle 客户端

    1. 下载所需的 Instant Client ZIP文件。
      [root@cdh01 ~]# mkdir /opt/oracle
      [root@cdh01 ~]# cd /opt/oracle
      [root@cdh01 oracle]# ll /opt/oracle
      total 82032
      -rw-r--r-- 1 root root 60704657 Dec 30 14:45 instantclient-basic-linux.x64-12.2.0.1.0.zip
      -rw-r--r-- 1 root root 23935897 Dec 30 17:01 instantclient-basiclite-linux.x64-12.2.0.1.0.zip
      -rw-r--r-- 1 root root  1562474 Dec 30 17:01 instantclient-jdbc-linux.x64-12.2.0.1.0.zip
      -rw-r--r-- 1 root root   310560 Dec 30 17:20 instantclient-odbc-linux.x64-12.2.0.1.0.zip
      -rw-r--r-- 1 root root   643089 Dec 30 14:53 instantclient-sdk-linux.x64-12.2.0.1.0.zip
      -rw-r--r-- 1 root root   834491 Dec 30 14:44 instantclient-sqlplus-linux.x64-12.2.0.1.0.zip
      -rw-r--r-- 1 root root   186409 Dec 30 14:53 instantclient-tools-linux.x64-12.2.0.1.0.zip
      
    2. 解压缩安装包
      [root@cdh01 oracle]# unzip instantclient-basic-linux.x64-12.2.0.1.0.zip
      [root@cdh01 oracle]# unzip instantclient-jdbc-linux.x64-12.2.0.1.0.zip
      [root@cdh01 oracle]# unzip instantclient-sdk-linux.x64-12.2.0.1.0.zip
      [root@cdh01 oracle]# unzip instantclient-sqlplus-linux.x64-12.2.0.1.0.zip
      [root@cdh01 oracle]# unzip instantclient-tools-linux.x64-12.2.0.1.0.zip
      
    3. 创建软链接
      [root@cdh01 oracle]# cd /opt/oracle/instantclient_12_2
      [root@cdh01 instantclient_12_2]# ln -s libclntsh.so.12.1 libclntsh.so
      [root@cdh01 instantclient_12_2]# ln -s libocci.so.12.1 libocci.so
      
    4. 安装 libaio 依赖包
      [root@cdh01 oracle]# yum install libaio
      
    5. 在 network/admin 子目录中创建 tnsnames.ora 文件
      [root@cdh01 oracle]# mkdir -p /opt/oracle/instantclient_12_2/network/admin
      [root@cdh01 oracle]# cd /opt/oracle/instantclient_12_2/network/admin
      [root@cdh01 admin]# cat tnsnames.ora
      ORCL =
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
          (CONNECT_DATA =
            (SERVER = DEDICATED)
            (SERVICE_NAME = orcl)
          )
        )
      
      orcl[本地实例名] =
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = TCP)(HOST = xx.xx.xx.xx[远程数据库IP地址])(PORT = 1521[远程服务器端口号]))
          (CONNECT_DATA =
            (SERVER = DEDICATED)
            (SERVICE_NAME = orcl[远程数据库服务名])
          )
        )
      
    6. 设置环境变量
      export LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2:$LD_LIBRARY_PATH
      export PATH=/opt/oracle/instantclient_12_2:$PATH
      export TNS_ADMIN=/opt/oracle/instantclient_12_1/network/admin
      
  2. 使用 RPM 文件离线安装 Oracle 客户端
    1. 下载所需的Instant Client RPM 软件包。
      [root@cdh01 ~]# mkdir /opt/oracle
      [root@cdh01 ~]# cd /opt/oracle
      [root@cdh01 oracle]# ll /opt/oracle
      total 84996
      -rw-r--r-- 1 root root 59865008 Dec 30 17:09 oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm
      -rw-r--r-- 1 root root 23679225 Dec 30 17:00 oracle-instantclient12.2-basiclite-12.2.0.1.0-1.x86_64.rpm   # 不需要
      -rw-r--r-- 1 root root   610222 Dec 30 17:00 oracle-instantclient12.2-devel-12.2.0.1.0-1.x86_64.rpm
      -rw-r--r-- 1 root root  1564169 Dec 30 16:59 oracle-instantclient12.2-jdbc-12.2.0.1.0-1.x86_64.rpm
      -rw-r--r-- 1 root root   311509 Dec 30 17:00 oracle-instantclient12.2-odbc-12.2.0.1.0-1.x86_64.rpm     # 不需要
      -rw-r--r-- 1 root root   828333 Dec 30 16:59 oracle-instantclient12.2-sqlplus-12.2.0.1.0-1.x86_64.rpm
      -rw-r--r-- 1 root root   161109 Dec 30 17:00 oracle-instantclient12.2-tools-12.2.0.1.0-1.x86_64.rpm
      
    2. 使用安装软件包yum。例如:
      [root@cdh01 oracle]# yum -y install oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm
      [root@cdh01 oracle]# yum -y install oracle-instantclient12.2-devel-12.2.0.1.0-1.x86_64.rpm
      [root@cdh01 oracle]# yum -y install oracle-instantclient12.2-jdbc-12.2.0.1.0-1.x86_64.rpm
      [root@cdh01 oracle]# yum -y install oracle-instantclient12.2-sqlplus-12.2.0.1.0-1.x86_64.rpm
      [root@cdh01 oracle]# yum -y install oracle-instantclient12.2-tools-12.2.0.1.0-1.x86_64.rpm
      
    3. 创建 tnsnames.ora 文件
      [root@cdh01 oracle]# mkdir -p /usr/lib/oracle/12.2/client64/lib/network/admin
      [root@cdh01 oracle]# cd /usr/lib/oracle/12.2/client64/lib/network/admin
      [root@cdh01 admin]# cat tnsnames.ora
      ORCL =
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
          (CONNECT_DATA =
            (SERVER = DEDICATED)
            (SERVICE_NAME = orcl)
          )
        )
      
      orcl[本地实例名] =
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = TCP)(HOST = xx.xx.xx.xx[远程数据库IP地址])(PORT = 1521[远程服务器端口号]))
          (CONNECT_DATA =
            (SERVER = DEDICATED)
            (SERVICE_NAME = orcl[远程数据库服务名])
          )
        )
      
    4. 设置环境变量
      export LD_LIBRARY_PATH=/usr/lib/oracle/12.2/client64/lib:$LD_LIBRARY_PATH
      export PATH=/usr/lib/oracle/12.2/client64/bin:$PATH
      export TNS_ADMIN=/usr/lib/oracle/12.2/client64/lib/network/admin
      
  1. 使用 sqlplus 连接 Oracle 数据库

    格式: sqlplus 用户名/密码@本地实例名 (as 身份)

    1. 数据库管理员登录
      sqlplus sys/123456@orcl as sysdba
      
    2. 普通用户登录
      [root@DSJ-TVM002 admin]# sqlplus admin/123456@orcl
      
      SQL*Plus: Release 12.2.0.1.0 Production on Mon Dec 30 18:43:40 2019
      
      Copyright (c) 1982, 2013, Oracle.  All rights reserved.
      
      
      Connected to:
      Oracle Database 11g Enterprise Edition Release 12.2.0.1.0 - 64bit Production
      With the Partitioning, OLAP, Data Mining and Real Application Testing options
      
      SQL> 
      

参考: https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html

你可能感兴趣的:(Linux 下安装 Oracle 客户端)