安装过程比较烦,第一次走通,要几小时,实里是烦,这里记下来一次安装的过程.
1 下载文件msodbcsql-11.0.2270.0.tar.gz和unixODBC-2.3.0.tar.gz 其中msodbcsql-11.0.2270.0.tar.gz是微软的Microsoft® ODBC Driver 11 for SQL Server® - RedHat Linux
这个版本,在微软网站就可以下载.而unixODBC-2.3.0.tar.gz是比较好下载的,注意的是不通使用unixODBC-2.3.1.tar.gz版本.把这两个文件都传到服务器上去.
2 在服务器上用命令解压这个文件
tar xvzf msodbcsql-11.0.2270.0.tar.gz
3 进入目录msodbcsql-11.0.2270.0,然后修改build_dm.sh,把其中的#!/bin/sh修改为#!/bin/bash然后保存.然后再把文件unixODBC-2.3.0.tar.gz放到目录msodbcsql-11.0.2270.0下
4 然后执行如下命令:
./build_dm.sh --download-url=file://unixODBC-2.3.0.tar.gz
然后出现了如下信息:
Enter 'YES' to have this script continue: YES Verifying processor and operating system ................................... OK Verifying wget is installed ................................................ OK Verifying tar is installed ................................................. OK Verifying make is installed ............................................ FAILED Downloading unixODBC 2.3.0 DriverManager ........................ NOT ATTEMPTED Unpacking unixODBC 2.3.0 DriverManager .......................... NOT ATTEMPTED Configuring unixODBC 2.3.0 DriverManager ........................ NOT ATTEMPTED Building unixODBC 2.3.0 DriverManager ........................... NOT ATTEMPTED Errors occurred. See the /tmp/unixODBC.13857.16035.16434/build_dm.log file for more details.说明没有安装make,那么我们需要安装make,如下命令:
sudo apt-get install make
./build_dm.sh --download-url=file://unixODBC-2.3.0.tar.gz
又出现了以下信息:
Enter 'YES' to have this script continue: YES Verifying processor and operating system ................................... OK Verifying wget is installed ................................................ OK Verifying tar is installed ................................................. OK Verifying make is installed ................................................ OK Downloading unixODBC 2.3.0 DriverManager ................................... OK Unpacking unixODBC 2.3.0 DriverManager ..................................... OK Configuring unixODBC 2.3.0 DriverManager ............................... FAILED Building unixODBC 2.3.0 DriverManager ........................... NOT ATTEMPTED Errors occurred. See the /tmp/unixODBC.18982.10186.27291/build_dm.log file for more details.我们
cat /tmp/unixODBC.18982.10186.27291/build_dm.log以后发现如下:
hecking for cc... no checking for cl.exe... no configure: error: in `/tmp/unixODBC.18982.10186.27291/unixODBC-2.3.0': configure: error: no acceptable C compiler found in $PATH See `config.log' for more details.说明没有安装编译需要的东西,那么装吧,可以使用这些信息(根据自己的需要装就可以了):
sudo apt-get install g++ sudo apt-get install build-essential安装完毕后,再执行
./build_dm.sh --download-url=file://unixODBC-2.3.0.tar.gz
等一小会儿,就会出现如下:
Enter 'YES' to have this script continue: YES Verifying processor and operating system ................................... OK Verifying wget is installed ................................................ OK Verifying tar is installed ................................................. OK Verifying make is installed ................................................ OK Downloading unixODBC 2.3.0 DriverManager ................................... OK Unpacking unixODBC 2.3.0 DriverManager ..................................... OK Configuring unixODBC 2.3.0 DriverManager ................................... OK Building unixODBC 2.3.0 DriverManager ...................................... OK Build of the unixODBC 2.3.0 DriverManager complete. Run the command 'cd /tmp/unixODBC.24387.18479.8923/unixODBC-2.3.0; make install' to install the driver manager.
cd /tmp/unixODBC.24387.18479.8923/unixODBC-2.3.0
然后就执行如下进入安装:
sudo ./configure sudo make sudo make install这样unixODBC就安装完毕了.
5 以上就是安装完毕了unixODBC,如果要知道配置文件的位置,使用以下命令:
odbc_config --odbcinstini
/usr/local/etc/odbcinst.ini
8 unixODBC安装好了以后,就开始安装msodbcsql,进入一开始的msodbcsql-11.0.2270目录,然后执行如下命令
ldd lib64/libmsodbcsql-11.0.so.2270.0 | grep not一般这个时候会出现如下信息:
libcrypto.so.10 => not found libssl.so.10 => not found libodbcinst.so.1 => not found说明有这三个库找不到,我现在开始解决这个问题.
首先看一下这个库libcrypto在那里,使用如下命令
locate libcrypto我电脑的输出如下:
/lib/x86_64-linux-gnu/libcrypto.so.1.0.0 /usr/lib/x86_64-linux-gnu/libcrypto.a /usr/lib/x86_64-linux-gnu/libcrypto.so /usr/lib/x86_64-linux-gnu/pkgconfig/libcrypto.pc说明我们机器上没有libcrypto.so.10,但是我们有libcrypto.so.1.0.0,那么我们做个链接不就完了.不过我们先装一下SSL
sudo apt-get install libssl-dev
然后进入目录/lib/x86_64-linux-gnu,然后执行如下:
sudo ln -s libssl.so.1.0.0 libssl.so.10 sudo ln -s libcrypto.so.1.0.0 libcrypto.so.10然后再进入目录msodbcsql-11.0.2270 再执行
ldd lib64/libmsodbcsql-11.0.so.2270.0 | grep not发现没有任何输入,那么以下的动态库
libodbcinst.so.1 => not found怎么也解决了?我也没有搞清楚.有空再看一下.目前,这个动态库是可以用了.
9 修改msodbcsql-11.0.2270目录下的文件install.sh,把其中的#!/bin/sh修改为#!/bin/bash然后保存.然后执行如下:
sudo ./install.sh install --force然后我们再看一下/usr/local/etc/odbcinst.ini 里面的内容:
[ODBC Driver 11 for SQL Server] Description=Microsoft ODBC Driver 11 for SQL Server Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-11.0.so.2270.0 Threading=1 UsageCount=1就从原来的空白,变成有如下内容了.为了能够查看每次连接的故障,我们可以在内容里加这个:
[ODBC Driver 11 for SQL Server] Description=Microsoft ODBC Driver 11 for SQL Server Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-11.0.so.2270.0 Threading=1 UsageCount=1 [ODBC] Trace = Yes TraceFile = /tmp/odbc.log
10 测试一下,是不是能够连接到服务器
sqlcmd -U username -S ip,port
其中username是数据库的用户名,ip,port是数据库服务器的地址.应该没有问题了,有问题mail我QQ:26696815
注意,以下是我引用的别人的信息:
写配置文件,建立自己的数据源unixODBC的配置文件主要是usr/local/etc/odbcinst.ini以及usr/local/etc/odbc.ini。前者用于配置驱动程序,后者用于保存系统DSN。
如果安装完毕发现编译的时候没有找到sql.h,则需要安装
sudo apt-get install unixodbc-dev