1300,“无效的utf8mb4字符串:'\\xe2\\x96\\x88\\xe2\\x96\\x88

vvppvyoh  于 2021-06-25  发布在  Mysql
关注(0)|答案(1)|浏览(475)

我已经准备好了 utf8mb4 在charset和db列中,当使用 pymysql . 在每次插入之前,我执行以下操作:

cursor.execute('SET NAMES utf8mb4')
cursor.execute('SET CHARACTER SET utf8mb4')

它会停止查询,但会发出警告,不会插入记录。我该如何解决它。连接设置如下:

connection = pymysql.connect(host=host,
                                     user=user,
                                     password=password,
                                     db=db_name,
                                     autocommit=True,
                                     charset='utf8mb4',
                                     cursorclass=pymysql.cursors.DictCursor)
5kgi1eie

5kgi1eie1#

请尝试以下方法:
使用 COLLATE utf8mb4_general_ci 对于列
使用 varchar(size) 数据类型而不是 TEXT 对于列
不要使用 str(column) 在阅读时,使用 x.encode('utf-8') 或者 decode('utf-8')

相关问题