依赖安装:
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,如若转载,请注明出处:http://www.178linux.com/16496