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

推荐订阅源

S
Schneier on Security
L
LangChain Blog
爱范儿
爱范儿
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
月光博客
月光博客
Engineering at Meta
Engineering at Meta
G
Google Developers Blog
罗磊的独立博客
阮一峰的网络日志
阮一峰的网络日志
Blog — PlanetScale
Blog — PlanetScale
宝玉的分享
宝玉的分享
GbyAI
GbyAI
T
The Exploit Database - CXSecurity.com
F
Full Disclosure
V
V2EX
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V2EX - 技术
V2EX - 技术
The Register - Security
The Register - Security
PCI Perspectives
PCI Perspectives
博客园 - 叶小钗
S
Secure Thoughts
Project Zero
Project Zero
P
Proofpoint News Feed
博客园 - 三生石上(FineUI控件)
U
Unit 42
T
Tor Project blog
美团技术团队
大猫的无限游戏
大猫的无限游戏
C
Cisco Blogs
S
Securelist
人人都是产品经理
人人都是产品经理
Cisco Talos Blog
Cisco Talos Blog
K
Kaspersky official blog
Microsoft Azure Blog
Microsoft Azure Blog
T
Threat Research - Cisco Blogs
N
News and Events Feed by Topic
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Forbes - Security
Forbes - Security
IT之家
IT之家
A
Arctic Wolf
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
腾讯CDC
TaoSecurity Blog
TaoSecurity Blog
博客园 - 【当耐特】
I
Intezer
N
News | PayPal Newsroom
Y
Y Combinator Blog
博客园_首页

博客园 - 夏日微风

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

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

参考文档