写python脚本插入数据库时,报了编码问题。
数据库表的设计各方面都是utf-8编码的,MySQLDb把数据编码为latin-1,查询网上的修改方式:
conn.set_character_set('utf8')
cure.execute('SET NAMES utf8;')
cure.execute('SET CHARACTER SET utf8;')
cure.execute('SET character_set_connection=utf8;')
"conn" is the result of MySQLdb.connect, and "cure" is the result of db.cursor().
“conn”是建立的连接对象,“cure”是连接的cursor对象。
参考链接 https://blog.csdn.net/brink_compiling/article/details/51233087