Linux下通過ODBC連接sqlserver
1、需求:
最近有個需求就是要在linux下連接(可以執行sql語句)sqlserver
2、環境
操作系統: Centos6.5
數據庫: SQLServer2014
數據庫有用戶admin,密碼是123456,數據庫庫名是chzh
3、注意:
MS從來沒有提供過SQLServer for Linux,所以也不要去嘗試在Linux系統安裝SQLServer,但是可以通過ODBC連接Windows系統的SQLServer數據庫;
4、所需軟件包:
Linux系統的ODBC
unixODBC-2.2.11.tar.gz ( http://www.unixodbc.org )
連接SQLServer或Sybase的驅動
freetds-stable.tgz ( http://www.freetds.org/ )
軟件包見附件
5、安裝配置
(必須在root下用戶安裝)
1、安裝unixODBC
# tar vxzf unixODBC-2.2.11.tar.gz
# cd unixODBC-2.2.11
# ./configure --prefix=/usr/local/unixODBC --enable-gui=no --enable-drivers=no --with-qt-dir=/usr/lib/qt-3.3
# make
# make install
2、安裝freetds
# tar vxzf freetds-stable.tgz
# cd freetds-0.64
# ./configure --prefix=/usr/local/freetds --with-unixodbc=/usr/local/unixODBC --with-tdsver=8.0
# make
# make install
3、配置freetds
# cd /usr/local/freetds
# vi etc/freetds.conf
修改成以下內容:
[global]
# TDS protocol version
tds version = 8.0
[SQLServer2014]
host = 10.0.0.3
port = 1433
tds version = 8.0
client charset = UTF-8
其中的[SQLServer2014]代表在客戶端使用的服務器名稱(在tsql命令中要加入-S SQLServer2014),host代表SQLServer服務器的IP地址,port代表端口.client charset 是客戶端使用的字符集, client charset 必需大於或等於服務端數據庫使用的字符集。
6、測試連接:
# /usr/local/freetds/bin/tsql -S 10.0.0.3 -U admin
locale is "zh_CN.UTF-8"
locale charset is "UTF-8"
Password: 123456
1>
在這里我們就可以輸入sql語句了。
附件列表