1.环境
1[root@bakdbserver ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.9 (Tikanga)
[root@bakdbserver ~]# uname -a
Linux bakdbserver 2.6.39-300.26.1.el5uek #1 SMP Thu Jan 3 18:31:38 PST 2013 x86_64 x86_64 x86_64 GNU/Linux
2.下载
2.1 unixODBC
下载地址:
http://www.unixodbc.org/
下载文件:
unixODBC-2.3.0.tar.gz
2.2 Oracle ODBC Driver
下载地址:
http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
下载文件:
instantclient-basic-linux.x64-11.2.0.3.0.zip
instantclient-odbc-linux.x64-11.2.0.3.0.zip
其他平台到下面地址下载:
http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
将所有文件上传至服务器的/opt/odbc/目录下。
3.安装unixODBC(root用户)
#cd /opt/odbc/
#tar xvf unixODBC-2.3.0.tar.gz
#cd /opt/odbc/unixODBC-2.3.0
#./configure
#make
#make install
(默认是被安装到/usr/local)
4.安装Oracle ODBC(root用户)
#cd /opt/odbc/
#unzip instantclient-basic-linux.x64-11.2.0.3.0.zip
#unzip instantclient-odbc-linux.x64-11.2.0.3.0.zip
(两个文件解压到同一个目录instantclient_10_2下)
#cd /opt/odbc/instantclient_11_2
#chmod 775 odbc_update_ini.sh
#./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
修改odbc目录的权限:
chown -R 775 /opt/odbc
5.配置本地服务名:
添加本地服务名。
$TNS_ADMIN/tnsnames.ora
或
$ORACLE_HOME/network/admin/tnsnames.ora
例如:
bi_195 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.5.195)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = cwdb)
)
)
如果是非Oracle用户,可以通过设置环境变量TNS_ADMIN来制定tnsnames.ora所在位置,当该改用户有对tnsnames.ora读的权限。
6.检查驱动配置
/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 =
7.添加oracle odbc配置(oracle用户):
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 =bi_195 #对应tnsnames.ora中配置的本地服务名
SQLGetData extensions = F
Translation DLL =
Translation ption = 0
DisableRULEHint = T
UserID =
8.设置环境变量(oracle用户):
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH: /opt/odbc/instantclient_11_2:/usr/local/lib
PATH=$PATH:/usr/local/bin
TNS_ADMIN(如果安装有oracle软件那么对应的就是$ORACLE_HOME/network/admin/目录,如果没有安装相应oracle软件,需要指定tnsnames.ora所在的目录,可选)
NLS_LANG(设定合适的字符集,可选)
9.测试(oracle用户)
+---------------------------------------+
[root@bakdbserver ~]# isql OracleODBC-11g bi bi -v
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL> select * from v$version;
+-----------------------------------------------------------------+
| BANNER |
+-----------------------------------------------------------------+
| Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi|
| PL/SQL Release 10.2.0.5.0 - Production |
| CORE 10.2.0.5.0 Production |
| TNS for Linux: Version 10.2.0.5.0 - Production |
| NLSRTL Version 10.2.0.5.0 - Production |
+-----------------------------------------------------------------+
SQLRowCount returns -1
5 rows fetched
测试方法:
isql <数据源名称> <用户名> <密码> -v
10.遇到的问题:
isql OracleODBC-11g system oracle -v
出错:
isql: symbol lookup error: /usr/lib/oracle/11.2/client/lib/libsqora.so.11.1: undefined symbol: SQLGetPrivateProfileStringW
这个问题就是unixODBC的版本问题啦,如果前面安装了unixODBC 2.3.0的话不会出现这个错误(开始装的unixODBC 2.3.2版本)
参考:
http://blog.itpub.net/23135684/viewspace-667126/
http://blog.csdn.net/karl_max/article/details/6896014