How to use Oracle Instant Client in Mac OS X Lion

on

升级到Mac OS X Lion以后,原先在Snow Leopard下运行正常的Oracle 10.2.0.4 64bit将无法正常工作,无论执行什么命令(比如sqlplus或者lsnrctl)都会报如下错误。

$ sqlplus
Segmentation fault: 11

在OTN Forum中有此问题的讨论,但是目前为止还没有任何可用的解决方案。Oracle对于Mac的支持一向很弱,而OS X最近的这次升级一定是更改了很多库文件,导致64bit的Oracle数据库/64bit的Oracle Instant Client均无法在OS X Lion中正常运行。

对于Oracle数据库而言,只有for MAC OS X on Intel x86-64版本存在,但是对于Oracle Instant Client却有32bit版本下载,因此如果急于在Mac OS X Lion中使用sqlplus的,可以先安装32bit版本。

安装和设置方法:
1. 从以下链接下载Instant Client for Mac OS X。
http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html
下载Version 10.2.0.4 (32-bit) 中的:
instantclient-basic-10.2.0.4.0-macosx-x86.zip
instantclient-sqlplus-10.2.0.4.0-macosx-x86.zip

2. 将两个zip文件都解压到一个文件夹中,比如文件夹名为instantclient,我将此文件夹转移到到/Applications/Utilities/下,在你的环境中,任何路径都可以。

3. 修改Mac用户的环境变量,直接修改User Home下的.bash_profile文件,添加如下行,其中的路径替换为你环境中的instantclient路径。

export DYLD_LIBRARY_PATH=/Applications/Utilities/instantclient/
export ORACLE_HOME=/Applications/Utilities/instantclient/
export SQLPATH=$ORACLE_HOME
export PATH=$PATH:/Applications/Utilities/instantclient/:.

4. 手动创建tns_admin目录,以及tnsnames.ora文件,其中的内容自己写。

mkdir -p $ORACLE_HOME/network/admin
vi $ORACLE_HOME/network/admin/tnsnames.ora

在我的环境中,用instantclient连接VirtualBox中的11gR2数据库。

localhost:~ Kamus$ sqlplus kamus@vbox-orcl-oel5

SQL*Plus: Release 10.2.0.4.0 - Production on Sat Jul 30 12:09:35 2011

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.

Enter password: 

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, Oracle Label Security and Real Application Testing options

SQL> 

备注:关于glogin.sql
默认解压完的instantclient-sqlplus-10.2.0.4.0-macosx-x86.zip是不包含目录结构的,因此glogin.sql在sqlplus执行的时候无法被正确调用,导致的结果就是比如show parameter命令的格式非常难看。因此需要手动做如下操作:
1. 创建bin目录,将sqlplus可执行文件mv到该目录中
2. 创建sqlplus/admin目录,将glogin.sql文件mv到该目录中
3. 修改用户.bash_profile文件,将instantclient/bin添加到PATH环境变量中

One Comment Add yours

  1. warldge says:

    Mac安装Oracle完整傻瓜式教程 比任何一个教程都好 blog.sina.com.cn/s/blog_be59e93c0102uyhu.html

Leave a Reply

Your email address will not be published. Required fields are marked *