1.安装ODBC数据包,可以通过手工编译的方式也可以通过rpm包的方式进行安装,本文选择rpm包的安装方式:
[root@boserver odbc]# ls -l
总计 1656
-rw-r--r-- 1 root root 298139 2014-08-27 unixODBC-2.2.11-10.el5.x86_64.rpm
-rw-r--r-- 1 root root 811785 2014-08-27 unixODBC-devel-2.2.11-10.el5.x86_64.rpm
-rw-r--r-- 1 root root 567659 2014-08-27 unixODBC-libs-2.2.11-10.el5.x86_64.rpm
[root@boserver odbc]# rpm -ivh unixODBC-2.2.11-10.el5.x86_64.rpm unixODBC-devel-2.2.11-10.el5.x86_64.rpm unixODBC-libs-2.2.11-10.el5.x86_64.rpm
warning: unixODBC-2.2.11-10.el5.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:unixODBC-libs ########################################### [ 33%]
2:unixODBC ########################################### [ 67%]
3:unixODBC-devel ########################################### [100%]
2.FreeTDS介绍
该工具是Linux下用于连接MSSQL Server和Sybase的免费ODBC 驱动.
FreeTDS is a set of libraries for Unix and Linux that allows your programs to natively talk to Microsoft SQL Server and Sybase databases.
Technically speaking, FreeTDS is an open source implementation of the TDS (Tabular Data Stream) protocol used by these databases for their own clients. It supports many different flavors of the protocol and three APIs to access it. Additionally FreeTDS works with other software such as Perl and PHP, providing access from those languages as well.
If you are looking for a Java implementation, we refer you to the jTDS project on SourceForge.
FreeTDS has many possible uses. It has been used by Unix/Linux webservers to present data stored in SQL Server to the web, to port SQL Server database code from NT to Unix, to import data into SQL Server from a Unix source, and to provide database access on platforms (such as realtime systems) that have no native drivers.
The FreeTDS C libraries are available under the terms of the GNU LGPL license. Consult COPYING.LIB in the distribution for details.
3.下载并安装FreeTDS.
wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-stable.tgz
tar -zxvf freetds-stable.tgz
cd freetds-0.91/
./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --enable-msdblib
make && make install
4.配置 unixODBC和FreeTDS
4.1向unixODBC 登记 FreeTDS 驱动
在 /etc/odbcinst.ini 中添加如下内容:
# Driver from FreeTDS package
# setup from FreeTDS package
[FREETDS]
Description = ODBC of FreeTDS for MS SQL 2000
Driver = /usr/local/freetds/lib/libtdsodbc.so
Setup = /usr/local/freetds/lib/libtds.so
FileUsage = 1
4.2在 FreeTDS 的配置文件中添加指向具体数据库的访问信息
修改 /usr/local/freetds/etc/freetds.conf,在最后添加如下信息:
[MYSQLSERVER]
host = 192.168.0.5
port = 1433
tds version = 8.0
client charset = UTF-8
测试是否安装配置成功:
[root@boserver bin]# /usr/local/freetds/bin/tsql -S MYSQLSERVER -U mytest
Password:
locale is "zh_CN.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1>
2> exit
4.3修改/etc/odbc.ini
[mydsn]
Driver = FREETDS
Description = SQLServer
Servername = MYSQLSERVER
UserName =
Password =
Database = mydb
测试:
[root@boserver bin]# isql mydsn username password -v
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL> quit
[root@boserver bin]#
5.至此ODBC数据源配置完成.