python MySQLdb中文乱码解决

来源:互联网 发布:淘宝大学闪电学院 编辑:程序博客网 时间:2024/05/21 10:14






python MySQLdb中文乱码解决

IDEA
http://ideaes.blog.sohu.com/119027683.html
#!/usr/bin/env python

#coding=gb2312

import MySQLdb

#mysql python 读取中文乱码解决

#db = MySQLdb.Connect(user,pwd,dbip,dbname)
db = MySQLdb.connect(host="localhost", user="root", passwd="root", db="ruby",use_unicode=0, charset='gb2312')
cur = db.cursor()
#cur.execute('set names gb2312')
cur.execute('select * from users')
lT=cur.fetchall()
print lT[0][1]
cur.close()
db.close()

原创粉丝点击