Linux 下用unixODBC连接Oracle数据库的配置

 

  • 服务器环境检查
[root@db11g ~]# cat /etc/issue

Red Hat Enterprise Linux Server release 6.5 (Santiago)

Kernel \r on an \m

[root@db11g ~]# uname -a

Linux db11g 2.6.32-431.el6.x86_64 #1 SMP Sun Nov 10 22:19:54 EST 2013 x86_64 x86_64 x86_64 GNU/Linux

 

  • 准备介质

无论安装与否,均需下载以下三个介质,下载时注意和服务器平台匹配(32位、64位)

  • unixODBC-2.3.0.tar.gz
  • instantclient-basic-linux.x64-11.2.0.3.0.zip
  • instantclient-odbc-linux.x64-11.2.0.3.0.zip

 

下载后,将三个介质传至/opt/odbc/目录下

  • 安装unixODBC(root用户执行)
[root@db11g ~]# cd /opt/odbc/

[root@db11g odbc]# tar xvf unixODBC-2.3.0.tar.gz

[root@db11g odbc]# cd /opt/odbc/unixODBC-2.3.0

[root@db11g odbc]# ./configure

[root@db11g odbc]#make

[root@db11g odbc]#make install

 

  • 安装Oracle ODBC(root用户执行)
[root@db11g odbc]# cd /opt/odbc/

[root@db11g odbc]# unzip instantclient-basic-linux.x64-11.2.0.4.0.zip

[root@db11g odbc]# unzip instantclient-odbc-linux.x64-11.2.0.4.0.zip

两个文件均解压到了instantclient_11_2下

[root@db11g odbc]# cd /opt/odbc/instantclient_11_2

[root@db11g odbc]# chmod 775 odbc_update_ini.sh

[root@db11g odbc]# ./odbc_update_ini.sh /usr/local

没有任何提示表示安装成功

 

odbc_update_ini.sh参数说明:
参数1:unixODBC DM安装路径。
参数2:驱动安装的绝对路径(可选)。默认为运行脚本的路径。
参数3:驱动名(可选),默认为Oracle 11g ODBC driver。
参数4:数据源名称(可选),默认为OracleODBC-11g。
运行完成后将添加一个DNS条目到$HOME/.odbc.ini , <DriverManager_HOME>/etc/odbcinst.ini,名称为:OracleODBC-11g

 

  • 配置本地服务名
[root@db11g odbc]#cd $ORACLE_HOME/network/admin

[root@db11g odbc]#vi tnsnames.ora

例:

test =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.20.151)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = zyr11g)

    )

  )

 

  • 检查驱动配置
[root@db11g odbc]#cat /usr/local/etc/odbcinst.ini

 

[Oracle 11g ODBC driver]

Description     = Oracle ODBC driver for Oracle 11g

Driver          = /u01/app/ora11g/product/11.2.0/db_1/odbc/utl/libsqora.so.11.1

Setup           =

FileUsage       =

CPTimeout       =

CPReuse         =

 

  • 配置oracle odbc配置(oracle用户执行)
[root@db11g odbc]#vi ~/.odbc.ini

[OracleODBC-11g]

Application Attributes = T

Attributes = W

BatchAutocommitMode = IfAllSuccessful

BindAsFLOAT = F

CloseCursor = F

DisableDPM = F

DisableMTS = T

Driver = Oracle 11g ODBC driver       #对应/usr/local/etc/odbcinst.ini中的驱动配置名称

DSN = OracleODBC-11g

EXECSchemaOpt =

EXECSyntax = T

Failover = T

FailoverDelay = 10

FailoverRetryCount = 10

FetchBufferSize = 64000

ForceWCHAR = F

Lobs = T

Longs = T

MetadataIdDefault = F

QueryTimeout = T

ResultSets = T

ServerName =test      #对应tnsnames.ora中配置的本地服务名

SQLGetData extensions = F

Translation DLL =

Translation ption = 0

DisableRULEHint = T

UserID =

 

  • 设置环境变量(oracle用户执行)

 

[root@db11g odbc]#vi ~/.bash_profile

# .bash_profile

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

        . ~/.bashrc

fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

export ORACLE_BASE=/u01/app/oracle

export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1

export ORACLE_UNQNAME=zyr11g

export ORACLE_SID=db11g

export LD_LIBRARY_PATH=/opt/odbc/instantclient_11_2:/usr/local/lib:$LD_LIBRARY_PATH

export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:/usr/local/bin:$PATH

 

  • 测试(oracle用户执行)

 

[oracle@db11g ~]$ isql OracleODBC-11g cs cs -v

+---------------------------------------+

| Connected!                            |

|                                       |

| sql-statement                         |

| help [tablename]                      |

| quit                                  |

|                                       |

+---------------------------------------+

SQL>

 

测试方法:

isql <数据源名称> <用户名> <密码> -v

数据源名称来自于oracle用户下的~/.odbc.ini配置文件

 

上一篇:DELL 电脑 ubuntu20.04系统安装(最新最简版)


下一篇:中标麒麟V6.0 X64下64位Oracle 11g 安装配置手册