db = MySQLdb.connect(myhost,myuser,mypass,mydb ) db.set_character_set(‘utf8‘) #连接时设置 ‘‘‘ set the default character set for the current connection character_set_client character_set_results ‘‘‘ cursor = db.cursor(cursorclass = MySQLdb.cursors.DictCursor) cursor.execute(‘SET NAMES utf8;‘) #使用游标设置 最终导致的结果是: current connection character_set_client character_set_results 统统都是utf8
时间: 2024-11-18 20:13:06