rhel6.7安装pymssql(通过Python连接MSsql数据库)

依赖安装:

freetds、python-devel、cython、Python3.x

1、安装freetds

tar -jxvf freetds-dev.0.99.134.tar.bz
cd freetds-dev.0.99.134
./configure --prefix=/usr/local/freetds --with-tdsver=7.0 --enable-msdblib --with-gnu-ld --enable-shared --enable-static
echo "/usr/local/freetds/lib" >> /etc/ld.so.conf.d/freetds.conf
ldconfig -v

2、安装Python3.x

tar -zxvf Python-3.5.1.tgz
cd Python-3.5.1
./configure
make && make install

3、安装cython

pip3 install cython

4、安装pymssql

export PYMSSQL_BUILD_WITH_BUNDLED_FREETDS=1
pip3 install pymssql

测试连接

#!/usr/local/bin/python3.5
import pymssql
conn = pymssql.connect(host="x.x.x.x", user="sa", password="password",database="sys", charset='utf8', port='1433', as_dict=False)
print ('connect ok....')
cursor = conn.cursor()
sql = 'SELECT column FROM table WHERE key=key_id;'
cursor.execute(sql)
row = cursor.fetchone()
print (row[0])
conn.close()

参考博客:http://leovlys.iteye.com/blog/2283832

原创文章,作者:facker,如若转载,请注明出处:https://www.178linux.com/16496

赞 (0)
fackerfacker
上一篇 2016-05-22 14:27
下一篇 2016-05-23 16:28

相关推荐

  • DNS高级应用之子域授权&区域转发

    一、环境准备:    1、准备三台测试服务器,划分如下:    主DNS服务器:eth0:192.168.10.203;负责mylinux.com域解析;确保可以正常解析      子域DNS服务器:eth0:192.168.10.120; 负责子域ops.mylinux.com解析; &…

    Linux干货 2015-06-01
  • linux基础知识

    基本命令,man自助使用手册,linux文件目录。

    Linux干货 2017-12-11
  • 交互式与非交互式的区别

    交互式与非交互式shell /登录shell于非登录shell 外网连不上,教室装修太吵,相关资料找不到,云云不知所云,托托症又犯了 登录shell_非登录shell // .bash_profile .bashrc profile 文件的作用的执行顺序 http://blog.csdn.net/robertaqi/archive/2010/04/04/54…

    Linux干货 2017-06-11
  • http

    http http:hyper text transfer protocol, 应用层协议, 80/tcp, 文本协议 html:hyper text mark language, 是一种编程语言,超文本标记语言; html格式示例: <html> <head> <title>TITLE</title> &lt…

    Linux干货 2017-06-04
  • 第八周作业

    shell脚本简用

    Linux干货 2017-11-27
  • Acheng学习宣言

    我是Acheng,我参加了马哥Linux运维网络班,从2016年9月开始我将跟随马哥学习Linux技术。我的学习宣言是:再努力也不为过!朝着活学活用,做到做精的方向努力吧! 

    Linux干货 2016-10-25