本文主要是介绍解决mysql中文乱码无法插入ERROR 1366,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
插入insert 语句会出现如下错误:
insert into tb_person(name,sex,age,card_id) values('jack','男',23,1);
ERROR 1366 (HY000): Incorrect string value: '\xC4\xD0' for column 'sex' at row 1
在cmd 输入 show variables like 'character%';
出现如下结果
+--------------------------+----------------------------------------------+
| Variable_name | Value |
+--------------------------+----------------------------------------------+
| character_set_client | gbk |
| character_set_connection | gbk |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | gbk |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | D:\mysql\mysql-5.7.19-winx64\share\charsets\ |
+--------------------------+----------------------------------------------+
会发现 character_set_database 为 latin1
将它修改为utf8格式 输入如下命令:
set character_set_database=utf8;
同时还需要修改 character_set_client 修改为 utf8,命令如下:
set character_set_client=utf8
最后 修改 character_set_result 的字符编码与数据库一致
插入中文字符成功
查看MySQL 编码
+--------------------------+----------------------------------------------+
| Variable_name | Value |
+--------------------------+----------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | gbk |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | gbk |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | D:\mysql\mysql-5.7.19-winx64\share\charsets\ |
+--------------------------+----------------------------------------------+
这篇关于解决mysql中文乱码无法插入ERROR 1366的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!