运维网's Archiver
论坛
›
Python
› python 连接数据库编码
dsfsfs
发表于 2017-4-24 13:15:05
python 连接数据库编码
python 连接mysql 数据库
conn=MySQLdb.connect(host=host, user=user, passwd=password, db=db, init_command="set names utf8")
然后用conn就是了,再也不用考虑encoding的事情。
还有一个好处是,如果中间timeout, MySQLdb自动重连时,可以保证新的链接仍然是utf-8。
据说这是豆瓣的解决方法。
页:
[1]
查看完整版本:
python 连接数据库编码