ubuntu執行下列語句:
** sudo vim /etc/mysql/my.cnf **
而後在裏面插入語句:python
[client] default-character-set=utf8 [mysqld] character-set-server=utf8 collation-server=utf8_general_ci
退出 vim
從新啓動mysql:
** sudo service mysql restart **mysql
db=MySQLdb.connect(user='...',db='...',passwd='...',host='...',charset='utf8')
# -*-coding:utf-8 -*- import sys reload(sys) sys.setdefaultencoding('utf-8')
t = cursor.fetchall() s = t[0][1].decode('utf-8')