关于mac osx上安装 freetds unixodbc 及安装碰到的问题 - Go语言中文社区

关于mac osx上安装 freetds unixodbc 及安装碰到的问题


from:http://tcspecial.iteye.com/blog/1972740


1.首先我们应该安装unixodbc


brew install unixodbc


2.然后我们安装freetds:


brew install freetds --with-unixodbc


3.然后我们需要先配置freetds中的数据源:


应该在 /usr/local/etc/freetds.conf


 #A typical Microsoft server

   [testdsn]                     # SQL Server数据源名称,可以任意取有意义的名称

   host=192.168.10.22   # 数据库主机

   port=1344                   #数据库监听端口

   tds version=8.0 #默认7.0


4.然后我们有了数据源,应该去odbc中配置odbcinst.ini和odbc.ini


odbcinst.ini的地址,我这里是:

AndyMacBookPro:lib andy$ sudo find / -name odbcinst.ini
Password:
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory
/usr/local/Cellar/unixodbc/2.3.2/etc/odbcinst.ini
/usr/local/etc/odbcinst.ini
AndyMacBookPro:lib andy$ ll /usr/local/etc/odbcinst.ini 
lrwxr-xr-x  1 andy  admin  41  6 30 20:41 /usr/local/etc/odbcinst.ini@ -> ../Cellar/unixodbc/2.3.2/etc/odbcinst.ini
AndyMacBookPro:lib andy$ 



odbcinst.ini中的libtdsodbc.so的路径要自己确定,我这里是位于:

#Driver=/usr/local/freetds/lib/libtdsodbc.so  #指定TDS驱动路径
Driver=/usr/local/Cellar/freetds/0.91/lib/libtdsodbc.so


odbcinst.ini:


[FREETDS]
Description=freetds driver
Driver=/usr/local/freetds/lib/libtdsodbc.so  #指定TDS驱动路径


Trace=yes
TraceFile=/tmp/odbc.log  # 启用ODBC日志记录


odbc.ini:


[testdsn]  # 数据源名称
Driver=FREETDS # 指向odbcinst.ini的驱动配置
Description=MSSQL Server
Servername=testdsn # 数据源名称
Database=sqlscada    #数据库名称



然后就配置结束了,我们可以是用freetds+unixodbc访问mssql了~~~



之前碰到了问题,freetds编译之后一直找不到libtdsodbc.so的问题,现在终于明白,


要先安装unixodbc,然后要在brew安装freetds的时候一定要加上:


brew install freetds--with-unixodbc


这样就可以了!


yes!





如果我们想要使用php来连接mssql数据库,可能会有问题:

因为我们的php的mssql扩展不存在,无法连接mssql数据库,该怎么办呢?

var_dump(function_exists(mssql_connect));


求助brew:

AndyMacBookPro:lib andy$ brew search php54
homebrew/php/php54-amqp     homebrew/php/php54-proctitle
homebrew/php/php54-apc     homebrew/php/php54-propro
homebrew/php/php54-apcu     homebrew/php/php54-protobuf
homebrew/php/php54-augmentedtypes     homebrew/php/php54-pspell
homebrew/php/php54-blitz     homebrew/php/php54-pthreads
homebrew/php/php54-boxwood     homebrew/php/php54-raphf
homebrew/php/php54-chdb     homebrew/php/php54-redis
homebrew/php/php54-couchbase     homebrew/php/php54-redland
homebrew/php/php54-crypto     homebrew/php/php54-riak
homebrew/php/php54-dbase     homebrew/php/php54-runkit
homebrew/php/php54-dbus     homebrew/php/php54-scrypt
homebrew/php/php54-dmtx     homebrew/php/php54-snappy
homebrew/php/php54-ev     homebrew/php/php54-solr
homebrew/php/php54-gearman     homebrew/php/php54-sphinx
homebrew/php/php54-geoip     homebrew/php/php54-spl-types
homebrew/php/php54-gmagick     homebrew/php/php54-ssh2
homebrew/php/php54-graphdat     homebrew/php/php54-stats
homebrew/php/php54-htscanner     homebrew/php/php54-stemmer
homebrew/php/php54-http     homebrew/php/php54-sundown
homebrew/php/php54-igbinary     homebrew/php/php54-svm
homebrew/php/php54-imagick     homebrew/php/php54-swoole
homebrew/php/php54-inclued     homebrew/php/php54-thrift
homebrew/php/php54-intl     homebrew/php/php54-tidy
homebrew/php/php54-ioncubeloader     homebrew/php/php54-timezonedb
homebrew/php/php54-jsmin     homebrew/php/php54-tokyotyrant
homebrew/php/php54-judy     homebrew/php/php54-twig
homebrew/php/php54-leveldb     homebrew/php/php54-uploadprogress
homebrew/php/php54-libevent     homebrew/php/php54-uuid
homebrew/php/php54-libvirt     homebrew/php/php54-varnish
homebrew/php/php54-lz4     homebrew/php/php54-vld
homebrew/php/php54-lzf     homebrew/php/php54-wbxml
homebrew/php/php54-mailparse     homebrew/php/php54-xcache
homebrew/php/php54-mcrypt     homebrew/php/php54-xdebug
homebrew/php/php54-memcache     homebrew/php/php54-xhgui
homebrew/php/php54-memcached     homebrew/php/php54-xhp
homebrew/php/php54-midgard2     homebrew/php/php54-xhprof
homebrew/php/php54-mongo     homebrew/php/php54-xmldiff
homebrew/php/php54-mosquitto     homebrew/php/php54-yac
homebrew/php/php54-msgpack     homebrew/php/php54-yaf
homebrew/php/php54-mysqlnd_ms     homebrew/php/php54-yaml
homebrew/php/php54-oauth     homebrew/php/php54-yar
homebrew/php/php54-opcache     homebrew/php/php54-yaz
homebrew/php/php54-parsekit     homebrew/php/php54-yp
homebrew/php/php54-pcntl     homebrew/php/php54-yrmcds
homebrew/php/php54-pdflib     homebrew/php/php54-zmq
homebrew/php/php54-pdo-dblib     homebrew/php/php54-zookeeper
homebrew/php/php54-pdo-pgsql     homebrew/php/php54
homebrew/php/php54-phalcon
AndyMacBookPro:lib andy$ 


让我们来安装php54-pdo-dblib:


AndyMacBookPro:lib andy$ brew install homebrew/php/php54-pdo-dblib
Cloning into '/usr/local/Library/Taps/homebrew/homebrew-php'...
remote: Reusing existing pack: 6225, done.
remote: Counting objects: 10, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 6235 (delta 3), reused 0 (delta 0)
Receiving objects: 100% (6235/6235), 1.25 MiB | 271.00 KiB/s, done.
Resolving deltas: 100% (3901/3901), done.
Checking connectivity... done.
Tapped 408 formulae
Cloning into '/usr/local/Library/Taps/homebrew/homebrew-dupes'...
remote: Reusing existing pack: 1270, done.
remote: Total 1270 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (1270/1270), 251.63 KiB | 28.00 KiB/s, done.
Resolving deltas: 100% (682/682), done.
Checking connectivity... done.
Tapped 38 formulae
Error: No available formula for zlib (dependency of php54-pdo-dblib)
Please tap it and then try again: brew tap homebrew/dupes
Searching taps...
AndyMacBookPro:lib andy$ 



AndyMacBookPro:lib andy$ brew tap homebrew/dupes
Warning: Already tapped!
AndyMacBookPro:lib andy$ brew tap homebrew/php
Warning: Already tapped!
AndyMacBookPro:lib andy$ brew install php54-pdo-dblib
Error: You must `brew link freetds' before php54-pdo-dblib can be installed
AndyMacBookPro:lib andy$ 




AndyMacBookPro:lib andy$ brew link freetds
Linking /usr/local/Cellar/freetds/0.91... 
Error: Could not symlink etc/pool.conf
Target /usr/local/etc/pool.conf
already exists. You may want to remove it:
  rm /usr/local/etc/pool.conf


To force the link and overwrite all conflicting files:
  brew link --overwrite freetds


To list all files that would be deleted:
  brew link --overwrite --dry-run freetds
AndyMacBookPro:lib andy$ brew link freetds
Linking /usr/local/Cellar/freetds/0.91... 
Error: Could not symlink bin/bsqldb
Target /usr/local/bin/bsqldb
already exists. You may want to remove it:
  rm /usr/local/bin/bsqldb


To force the link and overwrite all conflicting files:
  brew link --overwrite freetds


To list all files that would be deleted:
  brew link --overwrite --dry-run freetds
AndyMacBookPro:lib andy$  brew link --overwrite --dry-run freetds



我们想要安装php54-pdo-dblib,但是:

AndyMacBookPro:/ andy$ brew install php54-pdo-dblib
Error: You must `brew link freetds' before php54-pdo-dblib can be installed
AndyMacBookPro:/ andy$ brew link freetds
Linking /usr/local/Cellar/freetds/0.91... 
Error: Could not symlink share/man/man1/bsqldb.1
Target /usr/local/share/man/man1/bsqldb.1
already exists. You may want to remove it:
  rm /usr/local/share/man/man1/bsqldb.1


To force the link and overwrite all conflicting files:
  brew link --overwrite freetds


To list all files that would be deleted:
  brew link --overwrite --dry-run freetds
AndyMacBookPro:/ andy$ clear
AndyMacBookPro:/ andy$ brew link freetds
Linking /usr/local/Cellar/freetds/0.91... 
Error: Could not symlink share/man/man1/bsqldb.1
Target /usr/local/share/man/man1/bsqldb.1
already exists. You may want to remove it:
  rm /usr/local/share/man/man1/bsqldb.1


To force the link and overwrite all conflicting files:
  brew link --overwrite freetds


To list all files that would be deleted:
  brew link --overwrite --dry-run freetds
AndyMacBookPro:/ andy$ brew link --overwrite freetds
Linking /usr/local/Cellar/freetds/0.91... 42 symlinks created
AndyMacBookPro:/ andy$ 




我们可以看到brew link 这次终于成功了,是因为我到了/usr/local/share/ 中删掉了整个freetds-0.91目录才成功的,不然会一直报错。


然后我们终于可以开始安装php54-pdo-dblib了~~

AndyMacBookPro:/ andy$ brew install php54-pdo-dblib
==> Downloading http://www.php.net/get/php-5.4.30.tar.bz2/from/this/mirror
######################################################################## 100.0%
==> PHP_AUTOCONF="/usr/local/opt/autoconf/bin/autoconf" PHP_AUTOHEADER="/usr/local/opt/au
==> ./configure --prefix=/usr/local/Cellar/php54-pdo-dblib/5.4.30 --with-pdo-dblib=/usr/l
==> make
==> Caveats
To finish installing pdo_dblib for PHP 5.4:
  * /usr/local/etc/php/5.4/conf.d/ext-pdo_dblib.ini was created,
    do not forget to remove it upon extension removal.
  * Validate installation via one of the following methods:
  *
  * Using PHP from a webserver:
  * - Restart your webserver.
  * - Write a PHP page that calls "phpinfo();"
  * - Load it in a browser and look for the info on the pdo_dblib module.
  * - If you see it, you have been successful!
  *
  * Using PHP from the command line:
  * - Run "php -i" (command-line "phpinfo()")
  * - Look for the info on the pdo_dblib module.
  * - If you see it, you have been successful!
==> Summary
�  /usr/local/Cellar/php54-pdo-dblib/5.4.30: 3 files, 32K, built in 7.2 minutes
AndyMacBookPro:/ andy$ 


但是我们发现我们要装的是不是pdo-dblib这个东西,而是mssql这个扩展,所以,呵呵,上面的事情白做了,从头再来:




版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qdujunjie/article/details/36034245
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-03-01 22:24:17
  • 阅读 ( 1230 )
  • 分类:数据库

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢