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

本地正常,部署到服务器运行的时后,给数据库插入中文数据时会报错

在这里插入图片描述

第一步

首先在 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 

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

最后:问题解决

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DeathAndLife

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值