menu LittleJake's Blog
color_lens
avatar
Jake Liu
Never Settle
creative commons by-nc-sa
hit
Category
keyboard_arrow_down

© 2024 LittleJake's Blog.

萌ICP备20223020号

python使用Pymysql操作MySQL报错Incorrect string value

背景

系统:centos 7.6
数据库版本:MySQL8.0

发现问题

Python 使用Pymysql更新数据库时,遇到未知字符。

问题解决

当前列使用类型为longtext;utf8_general_ci
由于传入的字符包括各种符号、各种汉字之类的,utf8明显无法满足业务需求。
因此修改当前列为utf8mb4_general_ci,问题解决

扩展说明

参考MySQL8.0手册可以发现
https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-utf8mb4.html

  1. utf8mb4是4位的utf8编码,而通常utf8为三位,utf8mb4可以理解为utf8的超集。
  2. 支持扩展编码以及BMP
Buy me a beer
Jake Liu
Never Settle

Title: python使用Pymysql操作MySQL报错Incorrect string value

Author: Jake Liu

Origin:

Creative Commons License

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) For any re-post you must give appropriate credit.

文章遵循CC许可 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 转载请注明出处

Tag:python, MySQL, Incorrect string value, pymysql

评论区

Add a new comment.

Theme