数据库
首页 > 数据库> > 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`

作者:互联网

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)]
# 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
# 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

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

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

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

标签:Incorrect,xDF,set,mysql,character,server,client,报错,MySQL
来源: https://blog.csdn.net/weixin_50957373/article/details/121029232