惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
SegmentFault 最新的问题
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - Franky
有赞技术团队
有赞技术团队
Last Week in AI
Last Week in AI
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
aimingoo的专栏
aimingoo的专栏
Recent Announcements
Recent Announcements
雷峰网
雷峰网
T
Tor Project blog
博客园_首页
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The Register - Security
The Register - Security
T
The Blog of Author Tim Ferriss
Recorded Future
Recorded Future
V
Vulnerabilities – Threatpost
Project Zero
Project Zero
J
Java Code Geeks
AWS News Blog
AWS News Blog
Security Latest
Security Latest
Spread Privacy
Spread Privacy
T
Threatpost
博客园 - 三生石上(FineUI控件)
I
Intezer
G
Google Developers Blog
Scott Helme
Scott Helme
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The Hacker News
The Hacker News
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
NISL@THU
NISL@THU
A
Arctic Wolf
F
Full Disclosure
P
Proofpoint News Feed
G
GRAHAM CLULEY
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
N
Netflix TechBlog - Medium
C
Cybersecurity and Infrastructure Security Agency CISA
T
Threat Research - Cisco Blogs
B
Blog
IT之家
IT之家
MongoDB | Blog
MongoDB | Blog
L
LangChain Blog
Know Your Adversary
Know Your Adversary

博客园 - 夏日微风

mysql备份和恢复命令 urllib2下载时判断网页编码 使用setuptools自动安装python模块 php2python Python中文支持小结 WordPress安装步骤 centos 5.6 升级php到5.3 vsftp 的默认目录位置 Linux Develop Notes Linux Command Notes C#格式化数值结果表 - 夏日微风 - 博客园 证监会新年联欢会节目单(征求意见稿) 在.NET中打开ODBC“选择数据源”对话框 命案十三宗 看港剧,学穿衣 - 欧阳震华 看港剧,学穿衣 - 张家辉 - 胖矮个 看港剧,学穿衣 - 林保怡 - 小矮个 看港剧,学穿衣 - 罗嘉良 - 土蛋 看港剧,学穿衣 - 苏永康 - 斯文丑男
Python的MySQL库
夏日微风 · 2011-05-31 · via 博客园 - 夏日微风

Python真是个装b的语言,居然连mysql这么流行的数据库,都不提供官方支持

有第三方库,MySQLdb, 但这个库的帮助里面,只支持到mysql 5.1

操蛋的是,MySQLdb 库安装的时候,居然需要先安装一个mysql server

更操蛋的是,如果你安装的是高版本mysql,比如现在的5.5,居然不能直接安装,需要修改一堆配置

幸好,互联网上有其他的好心人,做了一个自动安装并且无需预先安装mysql server的版本

到这里下载吧:http://www.codegood.com/archives/129

sample code:

import MySQLdb, MySQLdb.cursors

def test():
    conn = MySQLdb.connect(host='localhost', user='root', passwd='', db='test', cursorclass=MySQLdb.cursors.DictCursor)
    cursor = conn.cursor()
    cursor.execute('SELECT * from test')
    row = cursor.fetchone()
    print row['field1']
    # print cursor.description
    cursor.close()
    conn.close()

if __name__=='main':
	test()

--------------------------------

还有第二个容易的选择:pymysql, http://code.google.com/p/pymysql/

pymysql库和MySQLdb的区别是: pymysql是纯python的,而MySQLdb是c写的

所以pymysql安装、使用起来相对容易一点

但pymysql,速度要慢一点

--------------------------------

另外一个可能的选择,pyodbc, http://code.google.com/p/pyodbc/wiki/FAQs

--------------------------------

参考文档