ubuntu中odbc 客户端环境搭建


本文以db2为列,其他系统及库类似

app–> unixODBC --> odbc driver --> db server

安装客户端

linuxx64_odbc_cli下载

添加数据源

解压后进入目录cfg,添加数据源

sudo cp db2cli.ini.sample db2cli.ini
sudo nano db2cli.ini
; Comment lines start with a semi-colon.
[133DB2]
Database=mydata
Protocol=TCPIP
Port=50000
Hostname=192.168.x.x

验证格式

test@develop:/opt/db2/clidriver$ bin/db2cli validate -dsn 133DB2

===============================================================================
Client information for the current copy:
===============================================================================

Client Package Type       : IBM Data Server Driver For ODBC and CLI
Client Version (level/bit): DB2 v11.5.5.0 (s2011011400/64-bit)
Client Platform           : Linux/X8664
Install/Instance Path     : /opt/db2/clidriver
DB2DSDRIVER_CFG_PATH value: <not-set>
db2dsdriver.cfg Path      : /opt/db2/clidriver/cfg/db2dsdriver.cfg
DB2CLIINIPATH value       : <not-set>
db2cli.ini Path           : /opt/db2/clidriver/cfg/db2cli.ini
db2diag.log Path          : /opt/db2/clidriver/db2dump/db2diag.log

===============================================================================
db2dsdriver.cfg schema validation for the entire file:
===============================================================================
.......

安装unixodbc

sudo apt install unixodbc
//api里面的sql.h需要用到编译的头文件
sudo apt install unixodbc-dev

注册driver及配置

查看odbc配置文件

test@develop:/opt/db2/clidriver$ odbcinst -j
unixODBC 2.3.6
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /home/test/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8

注册driver

sudo nano /etc/odbcinst.ini
# Example odbcinst.ini driver definition for DB2 Data Server Driver for ODBC and CLI
[DB2]
Description=DB2_ODBC_Driver
#your driver shared object is located.
Driver=/opt/db2/clidriver/lib/libdb2.so 

Fileusage=1                
# IBM recommend setting Dontdlclose to 1, which stops unixODBC unloading the ODBC Driver on disconnect.
# Note that in unixODBC 2.2.11 and later, the Driver Manager default for Dontdlclose is 1.
Dontdlclose=1 

配置DSN

nano ~/.odbc.ini
[133DB2]
Driver=DB2

测试连接

test@develop:~$ isql 133DB2 username password -v
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL> quit;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值