当前位置:网站首页>MySQL5. 7 insert Chinese data and report an error: ` incorrect string value: '\ xb8 \ XDF \ AE \ xf9 \ X80 at row 1`

MySQL5. 7 insert Chinese data and report an error: ` incorrect string value: '\ xb8 \ XDF \ AE \ xf9 \ X80 at row 1`

2022-04-23 07:12:00 Xiaoye is stupid!

MySQL5.7 Insert Chinese data , Report errors :Incorrect string value: ‘\xB8\xDF\xAE\xF9\x80 at row 1

  1. First check the character encoding of the database , Because the default download MySQL The character set of the database is latin1
show create database < Database name >
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. Modify the encoding format of the database
alter database < Database name > character set utf8;
mysql> alter database information_company character set utf8;
Query OK, 1 row affected (0.00 sec)
  1. If you insert data without protection, you should also report an error …
  2. At this time we need to modify my.ini file
  3. What I download is MySQL5.7my.ini The file defaults to C:\ProgramData\MySQL\MySQL Server 5.7
    [ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-rj3TNplQ-1635473580693)(/picture/ProgramData.png)]
  • open “my.ini”.( Try to back up before modifying ). find [client] Add below
    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
  • Find [mysqld] Add below
    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
  • Then copy a copy to us MySQL Installation directory ( Default installed in C:\Program Files\MySQL\MySQL Server 5.7
    [ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-Qx7veb65-1635473580696)(/picture/ The installation directory .png)]

  • The last restart mysql service

Right click this computer —> management
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-DUVrCAOn-1635473580698)(/picture/ service .png)]

Type in on the keyboard mysql, find mysql service , Click restart

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-GIjS6DmP-1635473580700)(/picture/ Restart .png)]

版权声明
本文为[Xiaoye is stupid!]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230606586222.html