当前位置:网站首页>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 .
边栏推荐
- MySQL common commands
- Installation and use of appscan
- Blockbuster | certik: Web3.0 industry safety report release in the second quarter of 2022 (PDF download link attached)
- win10下基于anaconda的detectron2安装
- 数据标准详细概述-2022
- Tutorial on the principle and application of database system (046) -- MySQL query (VIII): group by
- js的相关知识
- 北峰通信亮相中国(厦门)应急展|智能化通信手段强势吸睛!
- Are the top ten securities companies risky and safe to open accounts?
- IDEA 热部署(热加载)
猜你喜欢

【电赛训练】非接触物体尺寸形态测量 2020年电赛G题

Dark horse programmer - interface test - four day learning interface test - day 4 - postman reads external data files, reads data files, IHRM project practice, employee management module, adds employe

Classic example of C language - find the minimum number of banknotes

PostgreSQL snapshot optimization globalvis new system analysis (greatly enhanced performance)

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

Case error of MySQL branch statement

Classic example of C language - commodity inspection code

Pbootcms database conversion tutorial (SQLite to MySQL detailed tutorial)

How can dbcontext support the migration of different databases in efcore advanced SaaS system

Memory forensics nssctf otterctf 2018 (replay)
随机推荐
【数据挖掘工程师-笔试】2022年海尔 公司
【电赛训练】非接触物体尺寸形态测量 2020年电赛G题
Bean Validation自定义容器验证篇----06
Detectron2 installation based on Anaconda under win10
Image processing 1:rgb888_ YCbCr444
mysql 分支语句case报错
Centernet target detection model and centerfusion fusion target detection model
Tutorial on principles and applications of database system (039) -- MySQL query (I): syntax analysis of select command
vim常用命令
Educational Codeforces Round 132 (Rated for Div. 2) D. Rorororobot
Don't let Fujin Yibo see this
Table custom table encapsulation
Coloring old photos - deoldify get started quickly
Are the top ten securities companies risky and safe to open accounts?
[the 83rd fortnight of leetcode]
Tutorial on principles and applications of database system (043) -- MySQL query (V): Sorting Query Results
網絡系統實驗:ping不通的問題解决
Method of C language annotation
C language writing specification
落枕如何快速缓解