Python数据库查询中文乱码的问题处理

来源:互联网 发布:2016淘宝有哪些购物节 编辑:程序博客网 时间:2024/06/03 20:18

通过Python查询数据库中数据时,数据汇呈现乱码,只需要在连接串中指定数据编码就可以如“utf8”、“GBK”...

import pymysqldb=pymysql.connect(host="localhost",user="root",password="root",database="school_schema",charset="GBK")cursor=db.cursor()sqlstr="SELECT * FROM school_schema.course;"try:    cursor.execute(sqlstr)    courses=cursor.fetchall()except:    print("数据读取错误")else:    print(courses)db.close()以上内容来自其他网站,如涉及版权,请联系删除
原创粉丝点击