python 连接到 mysql
Sep 7th, 2008 by phpsir
python 连接到 mysql
环境: mysql 5.0 数据库编码是gbk
文件如下,采用gbk编码 windows 2003 中文版本下 ansi 就可以了
# -*- coding: gbk -*-
import MySQLdb
conn = MySQLdb.Connection(’localhost’, ‘root’, ‘’, ‘test’,charset=”gbk”)
cur = conn.cursor()
lines = cur.execute(”SELECT * FROM `discuz`.`mycdb_projects`”);
a = cur.fetchall()
for ab in a:
print ab[1]