Linux 配置 unixODBC 访问 Oracle 说明
一.安装 unixODBC
UnixODBC官网:
这里使用YUM安装,不多说:
http://blog.csdn.net/tianlesoftware/article/details/7302358
[root@rac1 mnt]# yum installunixODBC
[root@rac1 mnt]# yum installunixODBC-devel
确认unixODBC的安装,使用 isql命令,其是unixODBC自带的命令。可以使用这个命令验证unixODBC的配置。
[root@rac1 /]# isql --version
unixODBC 2.2.14
[root@rac1 /]# which isql
/usr/bin/isql
[root@rac1 /]# isql
**********************************************
* unixODBC - isql *
**********************************************
* Syntax *
* *
* isql DSN [UID [PWD]] [options] *
* *
* Options *
* *
* -b batch.(no prompting etc) *
* -dx delimit columns with x *
* -x0xXX delimit columns with XX, where *
* x is in hex, ie 0x09 is tab *
* -w wrap results in an HTML table *
* -c column names on first row. *
* (only used when -d) *
* -mn limit column display width to n *
* -v verbose. *
* -lx set locale to x *
* -q wrap char fields in dquotes *
* -3 Use ODBC 3 calls *
* -n Use new line processing *
* --version version *
* *
* Commands *
* *
* help - list tables *
* help table - list columns in table *
* help help - list all help options *
* *
* Examples *
* *
* isql WebDB MyID MyPWD -w < My.sql *
* *
* Each line in My.sql must contain *
* exactly 1 SQL command except for the *
* last line which must be blank (unless *
* -n option specified). *
* *
* Please visit; *
* *
* http://www.unixodbc.org *
* pharvey@codebydesign.com *
* nick@easysoft.com *
**********************************************
[root@rac1 /]#
二.下载安装unixODBC 连接Oracle 的驱动
ODBC Drivers 下载地址:
http://www.easysoft.com/developer/interfaces/odbc/index.html
这里的驱动也分两种,需要Oracle 客户端的ODBC-Oracle Driver (OCI version)和不需要Oracle客户端的ODBC-OracleDriver (WP version),
The EasysoftODBC-Oracle Driver (OCI version) uses Oracleclient software to access the Oracle database.
The EasysoftODBC-Oracle Driver (WP version), which does not use Oracle client software,provides direct access to Oracle, for use in solutions where minimising theclient footprint is a requirement.
因为我的测试环境上已经安装了oracle,所以我这里选择需要客户端的驱动。
[root@rac1 u01]# ls
app backup odbc-oracle-3.3.0-linux-x86-64-ul64.tar oswbb oswbb4.0.tar
安装odbc 驱动:
[root@rac1 u01]# tar -xvf odbc-oracle-3.3.0-linux-x86-64-ul64.tar
[root@rac1 u01]# cd odbc-oracle-3.3.0-linux-x86-64-ul64
[root@rac1odbc-oracle-3.3.0-linux-x86-64-ul64]# ls
all.tar install_check_root install_versioned tee
all.tar.md5sum install_check_tools licclient testlib
all.tar.sum install_init licenses_template unixodbc.tar
check_root.txt install_intro license.txt unixodbc.tar.md5sum
cmpver install_license licshell unixodbc.tar.sum
drv_template install_linkpaths names unixODBC_version.txt
ident install.ORACLE ORACLE_intro.txt uodbc
install install_other_products ORACLE_uodbcinstall.txt versioned
install_check_linux install_paths OSname.txt
install_check_products INSTALL.txt postinstall
--使用root用户安装,因为安装过程中需要root权限:
[root@rac1odbc-oracle-3.3.0-linux-x86-64-ul64]# ./install
--安装过程中要看很多问题,不想看的直接按回车跳过。
….
Option: 1
No valid licenses found on this machine
in /usr/local/easysoft//license/licenses
[0] Exit
[1] View existing licenses
[2] Oracle ODBC Driver V3.3
Please choose the product you would like alicense for by entering its item number or enter one of the other options.
--这里有3个选项,2是需要购买的,我们选择0退出:
Option: 0
Access to the ODBC Driver is performedutilising the unixODBC Driver Manager.
The Driver Manager is made aware of thelocation of the Easysoft ODBC-Oracle Driver via data sources.
The following section will create an Oracledata source based on the information entered at the following prompt.
--会提示我们创建一个基本的data source:
The created data source will be called'ORACLE'.
Do you wish to create a data source at thistime? (y/n) [y]:
It seems that you do not have ORACLE_HOMEdefined at this time
Is this because you intend to use an Oracle10g Instant Client (y/n) [y]:
Enter the name or IP address of the Oracleserver (i.e. server): 192.168.3.116
Enter the port the Oracle server islistening on (default 1521):
Enter the Oracle Service Name (i.e. test):DAVE
Enter an Oracle user name (i.e. system):system
Enter the Oracle password for system (i.e.manager): oracle
Writing new/usr/local/easysoft/oracle/dsn_template for Instant Client
Installing entry in odbcinst.ini file
Drivers already installed for unixODBC are:
[PostgreSQL]
[MySQL]
[ORACLE]
*****
WARNING:
It appears the Easysoft ODBC-Oracle Driverdriver is already registered
with unixODBC.
If you are reinstalling the ORACLE to adifferent install path you
may have to edit your odbcinst.ini file tocorrect it as the
following odbcinst commands to install thedriver will simply increase
the usage count and not affect the paths.
*****
Press the return key to continue
Running odbcinst command:
/usr/local/easysoft/unixODBC/bin/odbcinst-i -d -f drv_template
==========
odbcinst: Driver installed. Usage countincreased to 2.
Target directory is /etc
==========
You can now install a [ORACLE] data sourcefor unixODBC and
Easysoft ODBC-Oracle Driver.
However, unixODBC currently requires anodbc.ini file to exist before a
datasource can be added. This install willcreate /etc/odbc.ini if you
request the datasource to be created.
Install unixODBC/Easysoft ODBC-OracleDriver data source (y/n) [y]:
Running odbcinst command:
/usr/local/easysoft/unixODBC/bin/odbcinst-s -i -f /usr/local/easysoft/oracle/dsn_template
==========
==========
Congratulations. You have now completed theinstallation of the Easysoft
ODBC-Oracle Driver.
The full manual is available as a PDF orHTML from:
ftp://ftp.easysoft.com/pub/docs/oracle
and in /usr/local/easysoft/oracle/doc.
The HTML version of the manual is availableonline at:
http://www.easysoft.com/products/data_access/odbc_oracle_driver
NOTE:
If you installed this software as anon-root user you need to:
1. set the EASYSOFT_ROOT environmentvariable to
/usr/local/easysoft.
2. Set up your dynamic linker search pathto include
/usr/local/easysoft/lib
/usr/local/easysoft/unixODBC/lib
切换到oracle 用户,在~/.bashrc中添加如下环境变量:
exportLD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export SHLIB_PATH=/usr/local/easysoft/lib
export LIBPATH=/usr/local/easysoft/lib
--source 使修改生效:
rac1:/home/oracle> source ~/.bashrc
三.配置unixODBC 连接Oracle
3.1 修改/etc/odbcinst.ini 文件
[root@rac1odbc-oracle-3.3.0-linux-x86-64-ul64]# cat /etc/odbcinst.ini
[PostgreSQL]
Description=ODBC for PostgreSQL
Driver=/usr/lib/psqlodbc.so
Setup=/usr/lib/libodbcpsqlS.so
Driver64=/usr/lib64/psqlodbc.so
Setup64=/usr/lib64/libodbcpsqlS.so
FileUsage=1
[MySQL]
Description=ODBC for MySQL
Driver=/usr/lib/libmyodbc5.so
Setup=/usr/lib/libodbcmyS.so
Driver64=/usr/lib64/libmyodbc5.so
Setup64=/usr/lib64/libodbcmyS.so
FileUsage=1
[ORACLE]
Description=Easysoft ODBC Oracle Driver
Driver=/usr/local/easysoft/oracle/libesoracle.so
Setup=/usr/local/easysoft/oracle/libesoraclesetup.so
DontDLClose=1
FileUsage=1
UsageCount=2
--最后一部分是我们在安装时配置的。
3.2 修改/etc/odbc.ini文件
[root@rac1odbc-oracle-3.3.0-linux-x86-64-ul64]# cat /etc/odbc.ini
[ORACLE]
Driver=ORACLE
Database=//192.168.3.116:1521/DAVE
User=system
Password=oracle
METADATA_ID=0
ENABLE_USER_CATALOG=1
ENABLE_SYNONYMS=1
--测试:
[root@rac1 ~]# cd /usr/local/easysoft/oracle
[root@rac1 oracle]# ./checksys -d ORACLE
./checksys: error while loading sharedlibraries: libodbcinst.so.1: cannot open shared object file: No such file ordirectory
这里报错,查看一下:
[root@rac1 lib64]# pwd
/usr/lib64
[root@rac1 lib64]# ls libodbcinst.so*
libodbcinst.so libodbcinst.so.2 libodbcinst.so.2.0.0
[root@rac1lib64]# ll libodbcinst.so*
lrwxrwxrwx. 1 root root 20 Mar 4 16:17 libodbcinst.so -> libodbcinst.so.2.0.0
lrwxrwxrwx. 1 root root 20 Mar 4 16:17 libodbcinst.so.2 -> libodbcinst.so.2.0.0
-rwxr-xr-x. 1 root root 68928 Jul 9 2010libodbcinst.so.2.0.0
确实没有,我们手工link一下:
[root@rac1 lib64]# ln -s libodbcinst.so libodbcinst.so.1
--之前是用root用户来检测的,其实正确的应该是用Oracle 的安装用户来验证:
rac1:/usr/local/easysoft/oracle>./checksys -d ORACLE
started on Sun Mar 4 20:11:55 2012
./checksys -d ORACLE Using /home/oracle ashome directory.
Checking ORACLE_HOME....
ORACLE_HOME set to/u02/app/oracle/product/11.2.0/db_1.
Checking LD_LIBRARY_PATH....
LD_LIBRARY_PATH set to/u02/app/oracle/product/11.2.0/db_1/lib:/lib:/usr/lib:/usr/local/lib:/usr/local/lib:/usr/lib64.
Directory"/u02/app/oracle/product/11.2.0/db_1" exists.
Looking for file libeslicshr_r.so in pathsin /etc/ld.so.conf.
File libeslicshr_r.so in a directory in/etc/ld.so.conf.
File /usr/local/easysoft/lib/libeslicshr_r.soexists and is readable.
Looking for file libessupp_r.so in paths in/etc/ld.so.conf.
File libessupp_r.so in a directory in/etc/ld.so.conf.
File /usr/local/easysoft/lib/libessupp_r.soexists and is readable.
Looking for file libodbcinst.so in paths in/etc/ld.so.conf.
Looking for file libodbcinst.so in paths in/u02/app/oracle/product/11.2.0/db_1/lib:/lib:/usr/lib:/usr/local/lib:/usr/local/lib:/usr/lib64.
File libodbcinst.so on path/u02/app/oracle/product/11.2.0/db_1/lib:/lib:/usr/lib:/usr/local/lib:/usr/local/lib:/usr/lib64.
File /usr/lib64/libodbcinst.so exists andis readable.
File tnsnames.ora NOT on path/u02/app/oracle/product/11.2.0/db_1/network/admin:/etc.File .tnsnames.ora NOTon path /home/oracle.Could NOT find tnsnames.ora fileCannot continue tests -aborting.
--------------------
--------------------
Summary of findings:
--------------------
--------------------
1 : ERROR : File tnsnames.ora NOT on path/u02/app/oracle/product/11.2.0/db_1/network/admin:/etc.
2 : ERROR : File .tnsnames.ora NOT on path /home/oracle.
3 : ERROR : Could NOT find tnsnames.ora file
Check oracle client installed and configured. Does it work with
sqlplus.
4 : ERROR : Cannot continue tests - aborting.
Fix problems listed above and try again.
--这里的报警信息就是tnsnames.ora 的问题了。 我们用的是直接连接,忽略这个问题。
用isql 命令测试:
rac1:/usr/local/easysoft/oracle> isqlORACLE -v
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
--查询表:
SQL> select * from dave;
+----------------+---------------------+
| ID | NAME |
+----------------+---------------------+
| 1 | dave |
+----------------+---------------------+
SQLRowCount returns -1
1 rows fetched
说明:
Easysoft是收费的,这里只能试用。
在下载的时候选择购买,就可以看到easysoft for oracle driver的价格:一台机器要2800$, 也不便宜啊。
刚去官网看了一下,貌似也没有ODBC for linux的,只有JDBC. 起初本打算随便测试一下的,结果花了太多的时间来研究其他问题了,此篇到此结束,不研究了。
-------------------------------------------------------------------------------------------------------
版权所有,文章允许转载,但必须以链接方式注明源地址,否则追究法律责任!
Skype: tianlesoftware
Email: tianlesoftware@gmail.com
Blog: http://www.tianlesoftware.com
Weibo: http://weibo.com/tianlesoftware
Twitter: http://twitter.com/tianlesoftware
Facebook: http://www.facebook.com/tianlesoftware
Linkedin: http://cn.linkedin.com/in/tianlesoftware
-------加群需要在备注说明Oracle表空间和数据文件的关系,否则拒绝申请----
DBA1 群:62697716(满); DBA2 群:62697977(满) DBA3 群:62697850(满)
DBA 超级群:63306533(满); DBA4 群:83829929 DBA5群: 142216823
DBA6 群:158654907 DBA7 群:172855474 DBA总群:104207940