#coding:utf-8当前文件的编码格式
字符串在python内部是unicode存在的
unicode-->GBK编码 s.encode("GBK")
GBK-->unicode 解码 s.decode("GBK")
MySQLdb.connect(host="ip",user="user",passwd="ps",db="db",charset='gbk')
charset 把数据从GBK, decode解码成unicode.
MySQLdb.connect(host="ip",user="user",passwd="ps",db="db",init-command="set names gbk")
把数据编码成GBK.
curse.execute("set names gbk")
客户端的编码显示方式.
下面是对GBK数据库的python操作例子:
#!/usr/bin/python
#coding:utf-8
conn=MySQLdb.connect(host="host",user="user",passwd="pass",db="db",init_command='set names gbk',charset='utf8')