Python连接Mysql&&解决数据库汉字显示_MySQL
来源:动视网
责编:小采
时间:2020-11-09 19:36:03
Python连接Mysql&&解决数据库汉字显示_MySQL
Python连接Mysql&&解决数据库汉字显示_MySQL:python # -*- coding:utf-8 -*-import MySQLdb#连接db = MySQLdb.connect(host=192.168.0.1, user=root, passwd='password',
导读Python连接Mysql&&解决数据库汉字显示_MySQL:python # -*- coding:utf-8 -*-import MySQLdb#连接db = MySQLdb.connect(host=192.168.0.1, user=root, passwd='password',

python
# -*- coding:utf-8 -*-import MySQLdb#连接db = MySQLdb.connect(host="192.168.0.1", user="root", passwd='password', db="db_name", charset = "utf8")cursor = db.cursor()#执行cursor.execute("SELECT * FROM users")users = cursor.fetchall()#
输出for user in users: print user[0], user[1], user[2]在connect中添加charset='utf8'可以解决在查询数据库中出现的汉字显示为乱码或者'???'的情况。
Python连接Mysql&&解决数据库汉字显示_MySQL
Python连接Mysql&&解决数据库汉字显示_MySQL:python # -*- coding:utf-8 -*-import MySQLdb#连接db = MySQLdb.connect(host=192.168.0.1, user=root, passwd='password',