在linux有时候程序也需要连接windows服务器下的MS Sql-server数据库服务器,这个时候要需要使用odbc的驱动了.我目前知道有两种现有的方式(不包括自己动手写驱动的).第一种就是使用
unixODBC+FreeTDS 这种使用方法也挺多的,我没有使用过,不清楚.第二种方式就是unixODBC+Microsoft® ODBC Driver 11 for SQL Server® - RedHat Linux 注意不需要使用Microsoft® ODBC Driver 11 for SQL Server® - SUSE Linux ,因为后面这个驱动版本使用的libssl是0.9.8版本的,在ubuntu14.04上面,默认安装的是libssl1.0.0版本.所以最好使用unixODBC+Microsoft® ODBC Driver 11 for SQL Server® - RedHat Linux.可能大家有一个担心就是,用在RedHat 上面的包,在ubuntu14.04上面能不能行,我告诉你,可以,只需要注意一点点就可以了.所以只需要从微软下载RedHat6\msodbcsql-11.0.2270.0.tar.gz这个版本就可以了,注意下面的说明
Microsoft SQL Server 2008, 2008 R2, SQL Server 2012, SQL Server 2014 and Windows Azure SQL Database. Microsoft ODBC Driver 11 for SQL Server also comes with powerful tools - sqlcmd and bcp.
https://www.microsoft.com/en-us/download/details.aspx?id=36437
看上面的说明,需要的库包括如下:
glibc libgcc libstdc++ krb5-libs openssl libuuid
tar xvzf msodbcsql-11.0.2270.0.tar.gz.
./build_dm.sh --help
会失败,这是因为shell是为redhat设计的,所以在ubuntu下可以这么干,用vim修改这个build_dm.sh,第一行
#!/bin/sh
修改成
#!/bin/bash
然后就可以安装Microsoft® ODBC Driver 11 for SQL Server®了,用vim修改这个install.sh的第一行,以上面一样.然后执行命令如下:
./install.sh verify
./install.sh: line 233: rpm: command not found
Checking for 64 bit Linux compatible OS ..................................... OK
Checking required libs are installed ................................. NOT FOUND
unixODBC utilities (odbc_config and odbcinst) installed ............ NOT CHECKED
unixODBC Driver Manager version 2.3.0 installed .................... NOT CHECKED
unixODBC Driver Manager configuration correct ...................... NOT CHECKED
Microsoft ODBC Driver 11 for SQL Server already installed .......... NOT CHECKED
Microsoft ODBC Driver 11 for SQL Server files copied ........................ OK
Symbolic links for bcp and sqlcmd created ................................... OK
Microsoft ODBC Driver 11 for SQL Server registered ................... INSTALLED
由于这个driver是给Red Hat 用的,debian下的一些依赖库就不能被侦测到。需要做一些符号链接来让它找到依赖库的位置
ldd lib64/libmsodbcsql-11.0.so.2270.0 | grep not
会发现如下的问题:
libcrypto.so.10 => not found
libssl.so.10 => not found
这个时候到目录下,建立符号链接
cd /usr/lib/x86_64-linux-gnu
sudo apt-get install libssl-dev
sudo ln -s libssl.so.1.0.0 libssl.so.10
sudo ln -s libcrypto.so.1.0.0 libcrypto.so.10
ldd lib64/libmsodbcsql-11.0.so.2270.0 | grep not
就会发现没有问题了.这个时候还是会出现如下问题,
./install.sh: line 233: rpm: command not found
Checking for 64 bit Linux compatible OS ..................................... OK
Checking required libs are installed ................................. NOT FOUND
unixODBC utilities (odbc_config and odbcinst) installed ............ NOT CHECKED
unixODBC Driver Manager version 2.3.0 installed .................... NOT CHECKED
unixODBC Driver Manager configuration correct ...................... NOT CHECKED
Microsoft ODBC Driver 11 for SQL Server already installed .......... NOT CHECKED
Microsoft ODBC Driver 11 for SQL Server files copied ........................ OK
Symbolic links for bcp and sqlcmd created ................................... OK
Microsoft ODBC Driver 11 for SQL Server registered ................... INSTALLED
怎么办?不办了,强制装:
sudo ./install.sh install --force
显示如下:
/install.sh: line 233: rpm: command not found Checking for 64 bit Linux compatible OS ..................................... OK Checking required libs are installed ................................. NOT FOUND unixODBC utilities (odbc_config and odbcinst) installed ............ NOT CHECKED unixODBC Driver Manager version 2.3.0 installed .................... NOT CHECKED unixODBC Driver Manager configuration correct ...................... NOT CHECKED Microsoft ODBC Driver 11 for SQL Server already installed .......... NOT CHECKED Microsoft ODBC Driver 11 for SQL Server files copied ........................ OK Symbolic links for bcp and sqlcmd created ................................... OK Microsoft ODBC Driver 11 for SQL Server registered ................... INSTALLED看起来问题很大,其实用起来根本没有问题.
注意的是,不要用 tsql来测试,因为它会用kerbose认证,而默认kerbos好像启动不了,回头我要看一下这个方面的问题.用sqlcmd来测试是不是安装成功.看起来是可以的
用以下命令
sqlcmd -U username -S ip,port