Linux上配置Unix ODBC连接Oracle数据库
作者:eygle
日期:January 05, 2005
Oracle10g前,Oracle并不提供UNIX/Linux下的ODBC驱动,用的最为广泛的是UnixOdbc,UnixOdbc的配置不算复杂,但是如果不顺利的话也会遇到一些问题。
今天成功安装配置了UnixOdbc把步骤总结一下供参考。
UnixOdbc可以在官方站点上下载。
以下是测试及配置步骤:
首先你需要安装Oracle客户端,并且确认网络可达。
1.使用isql进行测试
[root@magic root]# 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 *
* --version version *
* *
* Notes *
* *
* isql supports redirection and piping *
* for batch processing. *
* *
* Examples *
* *
* cat My.sql | isql WebDB MyID MyPWD -w *
* *
* Each line in My.sql must contain *
* exactly 1 SQL command except for the *
* last line which must be blank. *
* *
* Please visit; *
* *
* http://www.unixodbc.org *
* pharvey@codebydesign.com *
* nick@easysoft.com *
**********************************************
[root@magic root]# isql --versio
unixODBC 2.2.10
[root@magic root]# which isql
/usr/bin/isql
2./etc/odbc.ini文件配置
[ODBC Data Sources]
test = Oracle ODBC Driver DSN
[default]
Driver = /usr/local/easysoft/oracle/libesoracle.so
[test]
Driver = /usr/local/easysoft/oracle/libesoracle.so
Description = Oracle
server = 172.16.1.21
ServerType = Oracle
Port = 1521
User = username
Password = password
Database = ava
SID = ava
METADATA_ID = 0
ENABLE_USER_CATALOG = 1
ENABLE_SYNONYMS = 1
[default]
Driver = /usr/local/easysoft/oracle/libesoracle.so
3. /etc/odbcinst.ini 文件配置
;
; odbcinst.ini
;
[test]
Description=ODBC for ORACLE
Driver = /usr/local/easysoft/oracle/libesoracle.so
[ODBC]
Trace=1
Debug=1
Pooling=No
4.sqlnet.ora文件配置
NAMES.DIRECTORY_PATH= (TNSNAMES, ONAMES, HOSTNAME)
5.tnsnames.ora文件配置
ava =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.18.21)(PORT = 1521))
)
(CONNECT_DATA =
(SID = ava)
)
)
6.测试
[root@magic admin]# isql test -v
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
7.启动LDAP
[root@magic admin]# /usr/local/libexec/slapd -d 5 -f /home/eygle/openldap/slapd.conf
@(#) $OpenLDAP: slapd 2.2.17 (Dec 29 2004 20:45:12) $
root@magic.hawa.cn:/home/eygle/openldap/openldap-2.2.17/servers/slapd
daemon_init:
daemon_init: listen on ldap:///
daemon_init: 1 listeners to open...
ldap_url_parse_ext(ldap:///)
daemon: IPv6 socket() failed errno=97 (Address family not supported by protocol)
daemon: initialized ldap:///
daemon_init: 2 listeners opened
slapd init: initiated server.
==>backsql_initialize()
<==backsql_initialize()
>>> dnNormalize:
=> ldap_bv2dn(cn=Subschema,0)
ldap_err2string
<= ldap_bv2dn(cn=Subschema)=0 Success
=> ldap_dn2bv(272)
ldap_err2string
....
==>backsql_open_db_conn()
backsql_open_db_conn(): connected, adding to tree
<==backsql_open_db_conn()
backsql_get_db_conn(): first call -- reading schema map
==>backsql_load_schema_map()
ldapinfo.dn_ru field exists in the schema
backsql_load_schema_map(): at_query "SELECT name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,
expect_return,sel_expr_u FROM ldap_attr_mappings WHERE oc_map_id=?"
<==backsql_load_schema_map()
<==backsql_get_db_conn()
==>backsql_free_db_conn()
backsql_free_db_conn(): closing db connection
==>backsql_close_db_conn()
<==backsql_close_db_conn()
<==backsql_free_db_conn()
<==backsql_db_open(): test succeeded, schema map loaded
slapd starting
启动成功.