Python 连接Sql Server数据库 MSSql
Python 想要和MSSql数据库进行交互,首先要下载名为"pymssql"的包,然后import该包即可。
地址:https://pypi.python.org/pypi/pymssql/2.1.0#downloads
百度云(3.4win32+64):http://pan.baidu.com/s/1eSyPO5c
下载后安装,系统会自动选择python所在文件夹,然后安装到python\Lis\site-packages文件夹中。
然后在python的IDLE中敲入,import pymssql。
如果没有报错,那就恭喜您安装成功。
安装成功后,我们使用如下语句和MSSql数据库交互。
import pymssql conn=pymssql.connect(host='192.168.0.184',user='sa',password='pwd',database='ShcemDW')
'''
如果和本机数据库交互,只需修改链接字符串
conn=pymssql.connect(host='.',database='Michael')
'''
cur=conn.cursor() cur.execute('select top 5 * from [dbo].[Dim_Area]')
#如果update/delete/insert记得要conn.commit()
#否则数据库事务无法提交
print (cur.fetchall()) cur.close() conn.close()
如上,我们完成了Python和数据库的交互。
Python 连接Sql Server数据库 MSSql的更多相关文章
- python连接sql server数据库实现增删改查
简述 python连接微软的sql server数据库用的第三方模块叫做pymssql(document:http://www.pymssql.org/en/stable/index.html).在官 ...
- python 连接 SQL Server 数据库
#!/usr/bin/python # -*- coding:utf-8 -*- import pymssql import pyodbc host = '127.0.0.1:1433' user = ...
- python 连接sql server数据库的示例代码
首先,到http://pymssql.sourceforge.net/下载pymssql模块,必须安装这个模块才可以用python连接mysql 以下是sql server的操作代码,需要注意字符集 ...
- Python连接SQL Server数据库 - pymssql使用基础
连接数据库 pymssql连接数据库的方式和使用sqlite的方式基本相同: 使用connect创建连接对象 connect.cursor创建游标对象,SQL语句的执行基本都在游标上进行 cursor ...
- python连接sql server数据库
记录一下pyodbc连接数据库的使用方法和注意事项,基于python2.7: 前提: pip install pyodbc .下载pyodbc包. pyodbc.connect('DRIVER ...
- Python 连接SQL Server数据库 - pymssql使用基础
1. 官方api http://www.pymssql.org/en/stable/ref/pymssql.html 我学习自这里
- Python3.7.1学习(八) Python访问SQL Server数据库
一.pip install pymssql即可安装pymssql库 二.Python连接SQL Server数据库 实例代码如下: # -*- coding:utf-8 -*-"&q ...
- python 使用pymssql连接sql server数据库
python 使用pymssql连接sql server数据库 #coding=utf-8 #!/usr/bin/env python#------------------------------ ...
- python 连接sql server
linux 下pymssql模块的安装 所需压缩包:pymssql-2.1.0.tar.bz2freetds-patched.tar.gz 安装: tar -xvf pymssql-2.1.0.tar ...
随机推荐
- Python3 中类的反射
1.针对类中方法的反射 # 反射的使用 class Dog(object): def __init__(self,name): self.name = name def eat(self): prin ...
- Android源码、内核编译
Android源码和内核的编译就是一场马拉松,每一个节点都耗时漫长,下载源码.编译源码.下载内核.编译内核,下载中途会断掉,编译中间会失败,求解再重来,又是一轮马拉松,于是每一步都要做好备份和记录,可 ...
- oracle 闪回区故障
之前为了验证rman,把数据库改为了归档备份,但闪回区却还是4G,结果自动备份在五一执行了,悲剧,幸好没出门.一顿乱搞,其实走了错误方向.思路: 提示untle free,将数据库闪回区先增加:alt ...
- Iterator 遍历器
1.遍历器(Iterator)是一种接口,为各种不同的数据结构提供统一的访问机制.任何数据结构只要部署Iterator接口,就可以完成遍历操作(即依次处理该数据结构的所有成员). 2.Iterator ...
- STL_ALGORITHM_H
sort_unique_copy /////////////////////////////////////////////////////////// // Copyright (c) 2013, ...
- Django 自定义模板标签 报错django.template.exceptions.TemplateSyntaxError: '####' is not a registered tag library. Must be one of:
我写代码遇到这个错误,但是发现程序没有写错,好像是程序有缓存,重新运行几次就好了. 自定义模板标签,可以不用写views,url直接通过自定义函数把变量传给模板. 具体实现: 1.在app下新建Pyt ...
- node mysql问题:Client does not support authentication protocol requested by server; consider upgrading MySQL client!
node后台 mysql处理模块(版本:2.16.0) 执行connect方法时报错: Client does not support authentication protocol requeste ...
- 2.Valid Parentheses (括号匹配)
Level: Easy 题目描述: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', ...
- HDU6301 Distinct Values (多校第一场1004) (贪心)
Distinct Values Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- vue.js路由学习笔记二
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...