当前位置:网站首页>Solve the problem that MySQL inserts Chinese garbled code into the table
Solve the problem that MySQL inserts Chinese garbled code into the table
2022-07-24 00:51:00 【CC who likes fruits】
List of articles
Preface
Use... On the command line MySQL Chinese garbled code when adding data to the table after creating the table , I installed MySQL The version is MySQL 5.7, stay MySQL 8.0 This problem will not occur after version , So it's based on MySQL 5.7 In terms of version
mysql> insert into student values(1002,' Zhang San ');
ERROR 1366 (HY000): Incorrect string value: '\xD5\xC5\xC8\xFD' for column 'name' at row 1
One 、 Why does this happen ERROR
This is from MySQL The default character set in is Latin1 Caused by , When we use Chinese to add to the table, there will be Chinese garbled , To report a mistake , produce ERROR

Two 、 Solution steps
1: Check the code command
Use the following command on the command line
show variables like 'character_%';
show variables like 'collation_%';

2. modify MySQL Under the data directory of my.ini The configuration file
Modify the configuration file using the advanced text editor , What I use here is Sublime Text 3, After opening and modifying with software such as Notepad, the file code may be changed to “ contain BOM head ” The coding , Thus, the service restart fails .
default-character-set=utf8 # Default character set
[mysqld] # In about 76 Row or so , Add under
...
character-set-server=utf8
collation-server=utf8_general_ci

3. restart MySQL service
Here you can manually shut down or use the command line to restart MySQL service , The following figure shows restart using the command line MySQL service 
4. Review the encoding command again
Continue to use the following commands on the command line
show variables like 'character_%';
show variables like 'collation_%';

5. Add Chinese data to the table again
Be careful
Pay attention here , Note that the character set of the previously created table is Latin1, So when adding Chinese, I will report ERROR, The solution here is to delete the database directly , Recreate Library , The default is utf8 La 
Recreate the database

Add Chinese data to the table after re creating the table

summary
So that's the solution MySQL Add data to the table and insert Chinese garbled code , Targeted only MySQL 5.7 edition ,MySQL 8.0 The default character set of the version is utf8, You can insert Chinese data directly into the table . The principle is also the default way to modify the character set ,utf8 Character set .
If you forget to change the default code , There will be a problem of garbled code . from MySQL 8.0 Start , The default code of the database is changed to utf8mb4 , Thus, the above garbled code problem is avoided .
边栏推荐
- Interviewer: if the order is not paid within 30 minutes after it is generated, it will be automatically cancelled. How to realize it?
- 黑马程序员-接口测试-四天学习接口测试-第四天-Postman读取外部数据文件,读取数据文件数据,iHRM项目实战,员工管理模块,添加员工,批量运行测试用例,生成测试报告,
- 如何在自动化测试中使用MitmProxy获取数据返回?
- C language book recommendation
- Testers who have been employed for 3 months are facing employment confirmation. Leaders: 1 year of work experience is packaged into 5 years, and the probation period is eliminated
- 多源文件方式去访问全局变量的方式(extern用法)
- [low code] limitations of low code development
- How can dbcontext support the migration of different databases in efcore advanced SaaS system
- SAP 电商云 Spartacus UI Store 相关的设计明细
- XXL job realizes the code parsing of email sending warnings (line by line code interpretation)
猜你喜欢

Testers who have been employed for 3 months are facing employment confirmation. Leaders: 1 year of work experience is packaged into 5 years, and the probation period is eliminated

黑馬程序員-接口測試-四天學習接口測試-第四天-Postman讀取外部數據文件,讀取數據文件數據,iHRM項目實戰,員工管理模塊,添加員工,批量運行測試用例,生成測試報告,

Classic examples of C language - adding two scores

Solve the error: uncaught (in promise) navigationduplicated: avoided redundant navigation to current location:“

Prometheus+node exporter+grafana monitoring server system resources

postman测试接口在URL配置正确的情况下出现404或者500错误

Detailed overview of data standards -2022

High number_ Chapter 1 space analytic geometry and vector algebra__ Two point distance

Interviewer: if the order is not paid within 30 minutes after it is generated, it will be automatically cancelled. How to realize it?

入职3个月的测试员面临转正,领导:1年工作经验包装成5年,试用期淘汰
随机推荐
Coloring old photos - deoldify get started quickly
PostgreSQL snapshot optimization globalvis new system analysis (greatly enhanced performance)
Tutorial on principles and applications of database system (043) -- MySQL query (V): Sorting Query Results
Expérience du système réseau: résoudre les problèmes de ping
[video game training] non contact object size and shape measurement 2020 video game G
黑馬程序員-接口測試-四天學習接口測試-第四天-Postman讀取外部數據文件,讀取數據文件數據,iHRM項目實戰,員工管理模塊,添加員工,批量運行測試用例,生成測試報告,
C language: deep analysis of const keyword
How to realize 485 wireless communication between multiple sensors and Siemens PLC?
Bert article translation
Robot dog back submachine gun shooting video fire, netizens shivering: stoooooooopppp!
Project scenario: NVIDIA SMI unable to datemine the device handle for GPU 0000:01:00.0: unknown error
T-seda code
A good habit to develop when writing SQL
How can dbcontext support the migration of different databases in efcore advanced SaaS system
Prometheus+node exporter+grafana monitoring server system resources
Communication module sorting (II) hc-05
MySQL client to server character set conversion
mysql 分支语句case报错
Tutorial on principles and applications of database system (041) -- MySQL query (III): setting query conditions
Classic example of C language - convert the input two digits into English