Home > Database > Mysql Tutorial > body text

Python连接Mysql&&解决数据库汉字显示_MySQL

WBOY
Release: 2016-06-01 13:06:09
Original
2056 people have browsed it

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]
Copy after login
在connect中添加charset='utf8'可以解决在查询数据库中出现的汉字显示为乱码或者'???'的情况。
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!