您的位置:首页 > 产品设计 > UI/UE

问题记录【Data truncation: Incorrect string value: '\xE4\xB8\x83\xE6\x98\x9F...'】

2020-06-28 05:08 453 查看
本地正常,部署到服务器运行的时后,给数据库插入中文数据时会报错

第一步

首先在 etc/my.cnf修改字符编码为utf8mb4

[root@iZ2zebh41nm7vqxyy35hiqZ jar]# cat /etc/my.cnf
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]

[mysqld]
init_connect='set collation_connection = utf8mb4_general_ci'
init_connect='set collation_database=utf8mb4_general_ci'
init_connect='set names utf8mb4'
init_connect='set character_set_connection=utf8mb4'
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
skip-character-set-client-handshake
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

[root@iZ2zebh41nm7vqxyy35hiqZ jar]#

结果还是报错,有点懵

第二步

更改数据库编码:

ALTER DATABASE 数据库名 CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

更改表编码:

ALTER TABLE 表名 CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

更改列编码:

ALTER TABLE 表面 CHANGE 列名 列名 VARCHAR( 36 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL

因为没多少数据,我直接删除整个表
只更新了数据库编码

最后:问题解决

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐