linux下安装pymssql
2024-09-10 03:34:50
WIN下安装PYMSSQL,由于我没有系统管理权限,无法安装,
那只好在LINUX下面安装罗。。
以下这个文章帮助我搞定。
http://blog.csdn.net/five3/article/details/16338191
各版本的下载地址:https://pypi.python.org/pypi/pymssql/
Windows可以下载installer文件,直接是编译好的,可以直接安装
Linux下需要安装几个基础类库:
Cpython:pip install Cpython ##Python包
freetds-dev:yum install freetds-devel.x86_64 / apt-get install freetds-dev ##linux包
最后安装pymssql: pip install pymssql
import pymssql conn = pymssql.connect(host=host, user=user, password=password, database=database, charset=', as_dict=False) cursor = conn.cursor() sql = "select * from payment where id in (59,60)" cursor.execute(sql) results = cursor.fetchall() for row in results: print row
from os import getenv import pymssql server = getenv("PYMSSQL_TEST_SERVER") user = getenv("PYMSSQL_TEST_USERNAME") password = getenv("PYMSSQL_TEST_PASSWORD") conn = pymssql.connect(server, user, password, "tempdb") cursor = conn.cursor() cursor.execute(""" IF OBJECT_ID('persons', 'U') IS NOT NULL DROP TABLE persons CREATE TABLE persons ( id INT NOT NULL, name VARCHAR(100), salesrep VARCHAR(100), PRIMARY KEY(id) ) """) cursor.executemany( "INSERT INTO persons VALUES (%d, %s, %s)", [(1, 'John Smith', 'John Doe'), (2, 'Jane Doe', 'Joe Dog'), (3, 'Mike T.', 'Sarah H.')]) # you must call commit() to persist your data if you don't set autocommit to True conn.commit() cursor.execute('SELECT * FROM persons WHERE salesrep=%s', 'John Doe') row = cursor.fetchone() while row: print("ID=%d, Name=%s" % (row[0], row[1])) row = cursor.fetchone() conn.close()
最新文章
- UVa 307 - Sticks
- ASP.NET中常用重置数据的方法
- Python之路【第十篇】:HTML -暂无等待更新
- Permutations,Permutations II,Combinations
- rsyslog 日志服务器端配置
- 基于Xcode8插件开发~一键检测处理头文件引用
- .opt,frm,.MYD,.MYI文件如何转为.sql文件?
- 赋给个人账户sudo的全部root执行权限
- Tarjan + bfs HYSBZ 1179Atm
- Angular6 Observable.fromEvent error: “Invalid event target”
- win7文件搜索技巧
- IntelliJ IDEA web项目 工程构建运行部署
- httpd基础知识
- 《Linux内核设计与实现》读书笔记 4 进程调度
- 洛谷P1600 天天爱跑步
- [Python设计模式] 第3~5章 单一职责原则/开放-封闭原则/依赖倒转原则
- Java8新特性之Stream
- Slickflow.NET 开源工作流引擎高级开发(二) -- 流程快速测试增值服务工具介绍
- webGl中实现clipplane
- 联通GWH-01路由猫超级用户登录方法