1 odbc简介
ODBC为异构数据库访问提供统一接口,允许应用程序以SQL为数据存取标准,存取不同DBMS管理的数据;使应用程序直接操纵DB中的数据,免除随DB的改变而改变。
2 确认odbc版本
确认使用语句: odbcinst --version
如果没有安装odbc,需要下载如下安装包来安装。
官网下载地址:
http://ftp.unixodbc.org/
3 安装odbc
3.1 解压安装包
[root@DM8 unixODBC-2.3.9]# tar -zxvf unixODBC-2.3.9.tar.gz
3.2 odbc安装过程
3.2.1 安装前检查环境gcc/make编译器
[root@DM8 unixODBC-2.3.9]# rpm -qa | egrep ‘gcc|make’
cmake-3.12.1-5.ky10.x86_64
gcc-gfortran-7.3.0-20190804.h30.ky10.x86_64
automake-1.16.1-6.ky10.noarch
gcc-7.3.0-20190804.h30.ky10.x86_64
libgcc-7.3.0-20190804.h30.ky10.x86_64
make-4.2.1-15.ky10.x86_64
cmake-data-3.12.1-5.ky10.noarch
cmake-filesystem-3.12.1-5.ky10.x86_64
gcc-c+±7.3.0-20190804.h30.ky10.x86_64
cmake-rpm-macros-3.12.1-5.ky10.noarch
3.2.2 编译源码包并安装它
[root@DM8 unixODBC-2.3.9]# less INSTALL
-
cd' to the directory containing the package's source code and type
./configure’ to configure the package for your system. If you’re
usingcsh' on an old version of System V, you might need to type
sh ./configure’ instead to preventcsh' from trying to execute
configure’ itself.Running `configure’ takes awhile. While running, it prints some
messages telling which features it is checking for. -
Type `make’ to compile the package.
-
Type `make install’ to install the programs and any data files and
documentation. -
You can remove the program binaries and object files from the
source code directory by typingmake clean'. To also remove the files that
configure’ created (so you can compile the package for
a different kind of computer), typemake distclean'. There is also a
make maintainer-clean’ target, but that is intended mainly
for the package’s developers. If you use it, you may have to get
all sorts of other programs in order to regenerate files that came
with the distribution.
[root@DM8 home]# cd unixODBC-2.3.9/
[root@DM8 home]#./configure
[root@DM8 home]# make
[root@DM8 home]# make install
[root@DM8 unixODBC-2.3.9]# odbcinst --version
unixODBC 2.3.9
4 达梦数据库连接ODBC
[root@DM8 unixODBC-2.3.9]# odbcinst -j
unixODBC 2.3.9
DRIVERS…: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
FILE DATA SOURCES…: /usr/local/etc/ODBCDataSources
USER DATA SOURCES…: /root/.odbc.ini
SQLULEN Size…: 8
SQLLEN Size…: 8
SQLSETPOSIROW Size.: 8
4.1 配置odbcinst.ini
指定驱动位置
在末尾加入如下内容:
cd /usr/local/etc
vi odbc.ini
[DM8 ODBC Driver]
Description = ODBC driver for DM8
Driver = /dmdba/dmdbms/bin/libdodbc.so
4.2 配置odbc.ini
数据源:加载驱动、主机、用户、密码
cd /usr/local/etc
vi odbc.ini
[dm8]
Description=DM ODBC DSN
Driver=DM8 ODBC Driver --与/etc/odbcinst.ini中的标题相同
SERVER=192.168.3.100
UID=SYSDBA
PWD=dmdba9999
TCP_PORT=5236
4.3 连接数据库
[dmdba@dca01 ~]$ isql dm8 -v
5 总结
首先检查odbc的版本,如果版本需要升级,根据INSTALL中的要求安装就可以了。连接odbc就是需要配置2个文件,这两个配置文件的位置由odbcinst -j里面指定了,不能改变。odbc.ini文件指定了需要连接的数据库的用户名和密码,这些信息如果填错就会报错如下: