ODBC(Open Database Connectivity,开放数据库互连)提供了一种标准的API(应用程序编程接口)方法来访问DBMS(Database Management System)。这些API利用SQL来完成其大部分任务。ODBC本身也提供了对SQL语言的支持,用户可以直接将SQL语句送给ODBC。ODBC的设计者们努力使它具有最大的独立性和开放性:与具体的编程语言无关,与具体的数据库系统无关,与具体的操作系统无关。微软公司在1993年以DLL集的方式发布了世界上第一个ODBC产品,现在成为了微软开放服务结构(WOSA,Windows Open Services Architecture)中有关数据库的一个组成部分。微软的ODBC产品其实就是一个ODBC的驱动管理器,提供一个ODBC应用程序到某种ODBC驱动的接口。
ODBC接口定义如下内容:
ODBC的模型组成如下图所示。ODBC应用通过ODBC API调用驱动管理器,驱动管理器可以是微软驱动管理器,也可以是unixODBC驱动管理器。驱动管理器同样通过ODBC API调用ODBC driver,ODBC driver使用数据库API通过网络通信连接到数据库。
Oracle ODBC Driver使用Oracle调用接口(Oracle Call Interface)客户端和服务端软件提交请求并接收从数据源的响应。OCI客户端和Oracle服务端之间使用Oracle网络服务通信协议通信。Oralce ODBC驱动负责在ODBC SQL语法和能够访问数据源的语法之间转换,使用通信正常进行。Oracle ODBC的驱动架构如下图所示。
官方地址下载 http://www.unixodbc.org/download.html
下载文件:unixODBC-2.3.4.tar.gz
安装:
./configure --prefix=/usr/local/unixODBC --sysconfdir=/etc
#默认安装路径为 /usr/local,通过 --prefix改变
#默认odbcinst安装在 {prefix}/etc,通过--sysconfdir改变到指定路径
make
make install
./configure的各选项及描述如下
option | description |
---|---|
–prefix | This defines where you want to install unixODBC. If you do not specify this it will default to /usr/local. If you do not want unixODBC all under a single directory you can use other configure options like –bindir, –sbindir etc for finer control. |
–sysconfdir | This defines where you want unixODBC configuration files to be stored. This defaults to /etc. The configuration files affected are odbcinst.ini (where ODBC drivers are defined), the system odbc.ini (where system data sources are defined) and ODBCDataSources (where system file DSNs are stored). |
–enable-gui | The default is “yes” if QT is found. If you want to build the GUI ODBC Administrator, odbctest and DataManager set this to “yes”(e.g. –enable-gui=yes). You will need QT libraries and header files to build the GUI components (see later). You should probably also set –with-x. NOTE In unixODBC 2.3.0, the default for –enable-drivers was changed to “no” and the GUI components were moved into a new project. |
–enable-threads | The default is “yes” if thread-support is found on your machine. All modern Linuxes will have pthreads support in glibc so it is probably best to leave this to default. |
–enable-readline | The default is “yes” if libreadline and its headers are found on your machine. This principally only affects unixODBC isql program. If readline support is found then you can edit text entered at the SQL prompt in isql. |
–enable-drivers | The default is “yes”. When enabled this will build all the ODBC drivers included with unixODBC. This includes MySQL, Postgres, MiniSQL and a text file driver. |
–enable-iconv | This defaults to “yes” if libiconv and its header files are found on your machine. If you build with iconv and access then unixODBC can do Unicode translations. |
官方下载地址 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
安装:
unzip instantclient-basic-linux.x64-11.2.0.3.0.zip
unzip instantclient-odbc-linux.x64-11.2.0.3.0.zip
#注意,上述两个文件解压到同一目录下。
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 , /etc/odbcinst.ini,名称为:OracleODBC-11g
#修改odbc目录的权限:
chown -R 775 /opt/odbc
vi /etc/profile
加入
export ORACLE_HOME=/opt/oracle
export LD_LIBRARY_PATH=/opt/oracle/lib
使设置立即生效
source /etc/profile
因为本地没有安装oracle 数据库,所以需要从安装oracle 数据库的目录弄三个文件过来。
[root@localhost admin]# pwd
/opt/oracle/network/admin
[root@localhost admin]# ls
listener.ora sqlnet.ora tnsnames.ora #就这三个文件,放到这个目录下
tnsnames.ora文件
BOSSDATA =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =192.168.1.107)(PORT = 1521)) #192.168.1.107 IP地址 ,端口号:1521
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = bossdata) #bossdata 全局数据名
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
listener.ora文件
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = \opt\oracle)#注意,这个是刚才配置的$ORACLE_HOME
(PROGRAM = extproc)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.107)(PORT = 1521)) #这个上面有说明
)
)
/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 =
测试方法:
isql <数据源名称> <用户名> <密码> -v
[root@bakdbserver ~]# isql OracleODBC-11g bi bi -v
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
测试表明,连接数据库成功。
参考资料:
http://www.unixodbc.org/download.html
http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
https://www.easysoft.com/developer/interfaces/odbc/linux.html#introduction
Linux下用unixODBC连接Oracle数据库的配置 http://blog.csdn.net/lichangzai/article/details/40304077
linux单独安装oracle客户端(instantclient) http://blog.csdn.net/caomiao2006/article/details/11901123