【Linux】freetds安装配置连接MSSQL

摘要:
[ root@zabbixserverfreetds-0.91 ]#./ configure--help“configure”配置FreeTDS0.91加载到任何类型的系统。用法:

我使用的是freetds-0.91,下载地址:http://pan.baidu.com/s/1hq68rZY

安装编译(根据需要unixodbc):

[root@zabbixserver / ]# tar zxvf freetds-stable.tgz
[root@zabbixserver / ]# cd freetds-0.91
[root@zabbixserver freetds-0.91]# ./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --enable-msdblib --enable-shared --enable-static --with-unixodbc=/usr/local/unixODBC
[root@zabbixserver freetds-0.91]# make && make install

如果unixODBC有报错:

[root@zabbixserver freetds-0.91]# ./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --enable-msdblib --enable-shared --enable-static --with-unixodbc=/usr/local/unixODBC
...
configure: error: sql.h not found
[root@zabbixserver freetds-0.91]# cp /usr/local/unixODBC/include/sql.h /usr/local/include/ 

编译说明:

【Linux】freetds安装配置连接MSSQL第1张【Linux】freetds安装配置连接MSSQL第2张
[root@zabbixserver freetds-0.91]# ./configure --help
`configure' configures FreeTDS 0.91 to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
  -h, --help              display this help and exit
      --help=short        display options specific to this package
      --help=recursive    display the short help of all the included packages
  -V, --version           display version information and exit
  -q, --quiet, --silent   do not print `checking...' messages
      --cache-file=FILE   cache test results in FILE [disabled]
  -C, --config-cache      alias for `--cache-file=config.cache'
  -n, --no-create         do not create output files
      --srcdir=DIR        find the sources in DIR [configure dir or `..']

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]

By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc.  You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
  --bindir=DIR            user executables [EPREFIX/bin]
  --sbindir=DIR           system admin executables [EPREFIX/sbin]
  --libexecdir=DIR        program executables [EPREFIX/libexec]
  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
  --libdir=DIR            object code libraries [EPREFIX/lib]
  --includedir=DIR        C header files [PREFIX/include]
  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
  --infodir=DIR           info documentation [DATAROOTDIR/info]
  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
  --mandir=DIR            man documentation [DATAROOTDIR/man]
  --docdir=DIR            documentation root [DATAROOTDIR/doc/freetds]
  --htmldir=DIR           html documentation [DOCDIR]
  --dvidir=DIR            dvi documentation [DOCDIR]
  --pdfdir=DIR            pdf documentation [DOCDIR]
  --psdir=DIR             ps documentation [DOCDIR]

Program names:
  --program-prefix=PREFIX            prepend PREFIX to installed program names
  --program-suffix=SUFFIX            append SUFFIX to installed program names
  --program-transform-name=PROGRAM   run sed PROGRAM on installed program names

System types:
  --build=BUILD     configure for building on BUILD [guessed]
  --host=HOST       cross-compile to build programs to run on HOST [BUILD]

Optional Features:
  --disable-option-checking  ignore unrecognized --enable/--with options
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  --disable-dependency-tracking  speeds up one-time build
  --enable-dependency-tracking   do not reject slow dependency extractors
  --disable-largefile     omit support for large files
  --enable-shared[=PKGS]  build shared libraries [default=yes]
  --enable-static[=PKGS]  build static libraries [default=yes]
  --enable-fast-install[=PKGS]
                          optimize for fast installation [default=yes]
  --disable-libtool-lock  avoid locking (might break parallel builds)
  --disable-libiconv      do not attempt to include libiconv
  --disable-rpath         do not hardcode runtime library paths
  --enable-krb5[=LIB]     enable Kerberos support, optionally with library
  --enable-sspi           enable SSPI support
  --disable-odbc          do not attempt to build odbc the driver
  --disable-apps          skip build of src/apps (including tsql)
  --disable-server        skip build of src/server directory
  --disable-pool          skip build of src/pool directory
  --enable-msdblib        for MS style dblib
  --enable-sybase-compat  enable increased Open Client binary compatibility
  --disable-threadsafe    disable calls to threadsafe fuctions
                          e.g.,gethostbyname_r
  --disable-debug         disable assert and other things
  --enable-extra-checks   enable extra checks on code
  --enable-developing     enable code still in develop
  --enable-odbc-wide      enable wide string support in odbc [experimental]
  --enable-distcheck-build
                          used internally for testing

Optional Packages:
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --with-pic              try to use only PIC/non-PIC objects [default=use
                          both]
  --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
  --with-gnu-ld           assume the C compiler uses GNU ld default=no
  --with-libiconv-prefix[=DIR]  search for libiconv in DIR/include and DIR/lib
  --without-libiconv-prefix     don't search for libiconv in includedir and libdir
  --with-tdsver=VERSION   TDS protocol version (4.2/4.6/5.0/7.0/7.1) [5.0]
  --with-iodbc=DIR        build odbc driver against iODBC in DIR
  --with-unixodbc=DIR     build odbc driver against unixODBC in DIR
  --with-odbc-nodm=DIR    build odbc using headers in DIR/include
  --with-gnutls           build with TLS support
  --with-openssl          --with-openssl=DIR build with OpenSSL (license NOT
                          compatible cf. User Guide)


Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  LIBS        libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
              you have headers in a nonstandard directory <include dir>
  CPP         C preprocessor

Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.

Report bugs to the package provider.
View Code

编译完修改freetds配置:

[ser2008]
        host = 100.10.10.100
        port = 1433
        tds version = 8.0
        client chaeset = UTF-8

测试连接:

[root@zabbixserver freetds-0.91]#  /usr/local/freetds/bin/tsql -S ser2008 -U user -P passwd
locale is "zh_CN.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1> use test_database
2> go
1> select * from test_table
2> go

unixODBC下载地址:http://www.unixodbc.org/

参考:http://www.cnblogs.com/trams/archive/2011/12/02/2272079.html

安装unixODBC:

[root@zabbixserver unixODBC-2.3.2 ]# ./configure --prefix=/usr/local/unixODBC --includedir=/usr/include --libdir=/usr/lib -bindir=/usr/bin --sysconfdir=/etc
[root@zabbixserver unixODBC-2.3.2 ]# make && make install

yum安装的,大致方法一样,但不建议,yum安装的配置文件位置:

[root@zabbixserver etc]# whereis odbcinst
odbcinst: /usr/bin/odbcinst /etc/odbcinst.ini

配置unixODBC:

参考http://blog.csdn.net/gzlaiyonghao/article/details/3838967

注意odbcinst.ini中的Driver名字要和odbc.ini中的一致,odbc.ini中的Server要和freetds中的Server名字一致

[root@zabbixserver etc]# vim odbcinst.ini 
[ODBC]
Trace           = Yes
TraceFile       = /tmp/sql.log
ForceTrace      = Yes
Pooling         = No
[SQLSERVER]
Description     = SQLSERVER
Driver          = /usr/local/freetds/lib/libtdsodbc.so
Driver64          = /usr/local/freetds/lib/libtdsodbc.so
Setup           = /usr/local/freetds/lib/libtds.so
Setup64           = /usr/local/freetds/lib/libtds.so
UsageCount      = 1
CPTimeout       = 5
CPReuse         = 5
FileUsage       = 1

[root@zabbixserver etc]# vim odbc.ini 
[jd_msg]
Driver          = SQLSERVER
Description     = SQLSERVER
Server          = ser2008
Database        = test_database
Port            = 1433

报错1:

[root@zabbixserver etc]# isql test_database user password  
isql: error while loading shared libraries: libodbc.so.2: cannot open shared object file: No such file or directory

参考http://blog.csdn.net/m_star_jy_sy/article/details/8530706

[root@zabbixserver etc]# echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib"  >> /etc/bashrc
[root@zabbixserver etc]# source /etc/bashrc

报错2:

[root@zabbixserver etc]# isql test_database user password 
[ISQL]ERROR: Could not SQLConnect

免责声明:文章转载自《【Linux】freetds安装配置连接MSSQL》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇SqlServer数据库脱机和分离的区别编写你自己的单点登录(SSO)服务下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Unity4、Unity5移动平台多线程渲染在部分安卓手机上会造成闪退

你看到的crash堆栈可能是这样的: SIGSEGV(SEGV_MAPERR)   #00  pc 0001276c                          /system/lib/libc.so          #01  pc 00013dcc                          /system/vendor/lib/egl/...

Android文件下载(实现断点续传)

本文将介绍在android平台下如何实现多线程下载,大家都知道,android平台使用java做为开发语言,所以java中支持的多线程下载方式在android平台下都支持,其中主要有两种方式可以实现多线程下载。 一种方式是使用很多个线程分别下载文件的不同部分,最后把所有下载完的文件合并成一个文件。另一种方式是使用java为我们提供的RandomAcces...

并不对劲的loj3111:p5359:[SDOI2019]染色

题目大意 有个2行n列的网格,c种颜色。 有些格子的颜色是固定的。 不能把相邻的格子染成同色,问剩下的格子的染色方案数模(10^9+9)。(n,cleq 10^5;) 题解 “相邻不同色”让人想到可以把染完色的段的两个右(左)端点染上的颜色记在状态里进行dp。 发现对于一段连续的没有颜色固定的格的列,它的染色方案只与它的长度和它前后两端的已染色的格的相同情...

WPF利用Image实现图片按钮

  之前有一篇文章也是采用了Image实现的图片按钮,不过时间太久远了,忘记了地址。好吧,这里我进行了进一步的改进,原来的文章中需要设置4张图片,分别为可用时,鼠标悬浮时,按钮按下时,按钮不可用时的图片,这里我只用了一张图片,利用C#的图片灰度处理自动获得不可用时的图片,利用图片的间距实现悬浮及按下效果。先上效果:(正常 悬浮 按下 不可用)   代码其...

阻止Bootstrap 模态框点击背景空白处自动关闭

问题描述 模态框点击空白处,会自动关闭,怎么阻止关闭事件呢? 解决方法 在HTML页面中编写模态框时,在div初始化时添加属性 aria-hidden=”true” data-backdrop=”static”,即可。 <!-- 模态框(Modal) --> <div class="modal fade" id="myModal" t...

springboot开启gzip压缩

springboot 2.x开启gzip压缩 1.application.yml配置 server: compression: enabled: true min-response-size: 1 mime-types: application/json 2.代码设置(application.yml配置与代码设置二选一) @...