当你遇到Error: ER_TRUNCATED_WRONG_VALUE_FOR_FIELD: Incorrect string value:
Error: ER_TRUNCATED_WRONG_VALUE_FOR_FIELD: Incorrect string value: ‘\xE6\x88\x91\xE4\xBB\xAC…’ for column ‘content’ at row 1
这种原因是字符集编码导致的。
1、验证字符集
首先进入mysql:
mysql -u root -p
进入之后输入以下:
show variables like ‘%character%’;
这里是输入命令之后的视图:
mysql> show variables like ‘%character%’;
±-------------------------±---------------------------+
| Variable_name | Value |
±-------------------------±---------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
±-------------------------±---------------------------+
8 rows in set (0.01 sec)
你会看到| character_set_server | latin1 |
就是这个character_set_server等于latin1导致的错误,需要手动改文件
2、进入my.cnf
vim /etc/my.cnf
编辑my.cnf
在[mysqld]下面
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect=‘SET NAMES utf8mb4’
3、重启mysql.
service mysql restart
更多内容请见原文,原文转载自:https://blog.csdn.net/weixin_44519496/article/details/120181907