MySQL5.7插入中文数据,报错:`Incorrect string value: ‘\xB8\xDF\xAE\xF9\x80 at row 1`

2021/10/31 19:12:02

本文主要是介绍MySQL5.7插入中文数据,报错:`Incorrect string value: ‘\xB8\xDF\xAE\xF9\x80 at row 1`,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

MySQL5.7插入中文数据,报错:Incorrect string value: ‘\xB8\xDF\xAE\xF9\x80 at row 1

  1. 首先检查数据库的字符编码,因为默认下载的MySQL数据库的字符集为latin1
show create database <数据库名>
mysql> show create database information_company;
+---------------------+------------------------------------------------------------------------------+
| Database            | Create Database                                                              |
+---------------------+------------------------------------------------------------------------------+
| information_company | CREATE DATABASE `information_company` /*!40100 DEFAULT CHARACTER SET latin1 */ |
+---------------------+------------------------------------------------------------------------------+
1 row in set (0.00 sec)
  1. 修改数据库的编码格式
alter database <数据库名> character set utf8;
mysql> alter database information_company character set utf8;
Query OK, 1 row affected (0.00 sec)
  1. 然后不保护以外的话插入数据应该还会报错…
  2. 这个时候我们就需要修改my.ini文件
  3. 本人下载的是MySQL5.7my.ini文件默认是在C:\ProgramData\MySQL\MySQL Server 5.7
    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-rj3TNplQ-1635473580693)(/picture/ProgramData.png)]
  • 打开“my.ini”。(修改之前尽量备份)。找到[client]在下面添加
    default-character-set=utf8mb4
# The following options will be read by MySQL client applications.
# Note that only client applications shipped by MySQL are guaranteed
# to read this section. If you want your own MySQL client program to
# honor these values, you need to specify it as an option during the
# MySQL client library initialization.
#
[client]
default-character-set=utf8mb4
  • 在找到[mysqld]在下面添加
    character-set-server=utf8mb4
# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this 
# file.
#
# server_type=3
[mysqld]
character-set-server=utf8mb4
# collation-server=utf8_general_ci
  • 然后拷贝一份到我们MySQL的安装目录(默认安装在C:\Program Files\MySQL\MySQL Server 5.7
    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Qx7veb65-1635473580696)(/picture/安装目录.png)]

  • 最后重启mysql服务

右键此电脑 —> 管理
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-DUVrCAOn-1635473580698)(/picture/服务.png)]

在键盘上敲入mysql,找到mysql服务,点击重新启动

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-GIjS6DmP-1635473580700)(/picture/重新启动.png)]



这篇关于MySQL5.7插入中文数据,报错:`Incorrect string value: ‘\xB8\xDF\xAE\xF9\x80 at row 1`的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程