好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

python中mysql模块的内存泄露和中文乱码详解

mysql-python的连接时,默认大家会写成

解决方法是强制指定use_unicode=False。即:

con=MySQLdb.connect(user='xxx',passwd='xxx',host='xxx',port=6600,charset='gbk',use_unicode=False) 

这样既不会有内存泄露,也不需要在 输出文件时进行编码。也回避了python的codec不能解析mysql gbk里面存放的字符串的问题。 最后对于mysql4,我们可以将charset参数留空:

con=MySQLdb.connect(user='xxx',passwd='xxx',host='xxx',port=6600,use_unicode=False) 

这样就完美解决了这个问题,哈哈

查看更多关于python中mysql模块的内存泄露和中文乱码详解的详细内容...

  阅读:42次