Linux 配置 unixODBC 訪問 MS SQL Server 說明

來源:互聯網
上載者:User

一.安裝 unixODBC

這個使用YUM安裝一下,不多說:

Linux 使用光碟片搭建 本地 YUM 伺服器

[root@rac1 mnt]# yum install unixODBC     

[root@rac1 mnt]# yum install unixODBC-devel

 

確認unixODBC的安裝,使用 isql命令,其是unixODBC內建的命令。可以使用這個命令驗證unixODBC的配置。

 

[root@rac1 /]# isql --version

unixODBC 2.2.14

[root@rac1 /]# which isql

/usr/bin/isql

[root@rac1 /]# isql

 

**********************************************

* unixODBC - isql                            *

**********************************************

* Syntax                                     *

*                                            *

*     isql DSN [UID [PWD]] [options]       *

*                                            *

* Options                                    *

*                                            *

* -b        batch.(no prompting etc)        *

* -dx       delimit columns with x          *

* -x0xXX    delimit columns with XX, where  *

*           x is in hex, ie 0x09 is tab     *

* -w        wrap results in an HTML table   *

* -c        column names on first row.      *

*           (only used when -d)             *

* -mn       limit column display width to n *

* -v        verbose.                        *

* -lx       set locale to x                 *

* -q        wrap char fields in dquotes     *

* -3        Use ODBC 3 calls                *

* -n        Use new line processing         *

* --version version                         *

*                                            *

* Commands                                   *

*                                            *

* help - list tables                         *

* help table - list columns in table         *

* help help - list all help options          *

*                                           *

* Examples                                   *

*                                            *

*     isql WebDB MyID MyPWD -w < My.sql    *

*                                            *

*     Each line in My.sql must contain     *

*     exactly 1 SQL command except for the *

*     last line which must be blank (unless *

*     -n option specified).                *

*                                            *

* Please visit;                              *

*                                            *

*     http://www.unixodbc.org              *

*     pharvey@codebydesign.com             *

*     nick@easysoft.com                    *

**********************************************

 

[root@rac1 /]#

 

二.安裝 FreeTDS

freeTDS官網地址:http://www.freetds.org/

FreeTDS is a setof libraries for Unix and Linux that allows your programs to natively talk toMicrosoft SQL Server and Sybase databases.

--FreeTDS是Unix 和Linux library的一個集合,通過FreeTDS可以串連到MicrosoftSQL Server 和 Sybase DB。

 

2.1 下載freeTDS:

[root@rac1 ~]# wget http://ibiblio.org/pub/Linux/ALPHA/freetds/current/freetds-current.tgz

--2012-03-06 10:14:43-- http://ibiblio.org/pub/Linux/ALPHA/freetds/current/freetds-current.tgz

Resolving ibiblio.org... 152.19.134.40

Connecting toibiblio.org|152.19.134.40|:80... connected.

HTTP request sent, awaiting response... 200OK

Length: 2192516 (2.1M) [application/x-gzip]

Saving to: “freetds-current.tgzâ€

 

100%[==========================================================>]2,192,516   43.7K/s   in 37s    

 

2012-03-06 10:15:21 (58.5 KB/s) -“freetds-current.tgz†saved [2192516/2192516]

2.2 安裝freeTDS:

FreeTDS 的安裝協助,可以參考:

unixODBC - MS SQL Server/PHP

http://www.unixodbc.org/doc/FreeTDS.html 

[root@rac1 ~]# tar xzf freetds-current.tgz

 

--查看configure的協助文檔:

[root@rac1 freetds-0.92.dev.20120305]# ./configure --help

 

--官網提供的方法:
# ./configure --with-tdsver=8.0--with-unixodbc=/usr/local 
# make 
# make install

 

注意這裡:

如果 unixODBC是源碼安裝, 則–with-unixodbc=/usr/local
如果 unixODBC是rpm安裝, 則不需要該選項

 

我們的unixODBC 是通過RPM包安裝的,所以這裡我們省略這個選項,直接configure。

 

# ./configure --with-tdsver=8.0 --prefix=/usr/local/freetds --enable-msdblib  --with-gnu-ld  --enable-shared  --enable-static

--這次configure成功。這裡我們將freetds 安裝到/usr/local 目錄下。

 

然後make:

# make 
# make install

 

2.3 配置環境變數

將freetds的庫檔案所在路徑配置到LD_LIBRARY_PATH參數中: 
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/freetds/lib/: 

設定bin路徑 
$vi /root/.bashrc 
新增內容如下: 
export FREETDS=/usr/local/freetds 
export $PATH="$PATH:$FREETDS/bin" 

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/freetds/lib

  • 1
  • 2
  • 3
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.