当前位置:网站首页>[MySQL series] "once and for all" solves the problem of "inserting Chinese data" in MySQL
[MySQL series] "once and for all" solves the problem of "inserting Chinese data" in MySQL
2022-07-22 14:52:00 【Oh, it's Xiao Zhang】
Catalog
🥩🥩 One 、 First confirm the character set of the current database
Two 、 Find the configuration file
3、 ... and 、 Modify the configuration file
Other situations that may occur
Problem generation
As shown above , But you are happy to knock the above SQL When the sentence is , Found that all succeeded ;
But , But you want to Using insert statements Show the students Insert Chinese data When ,
But I found that there was an error ;
At first glance ,
" Why , My grammar format is correct , Why is there a mistake ? "
Take another look ,
" That's right! , It's exactly the same as the sentence in the book , Why is it still wrong ? "
Cause of occurrence
We all know , When the database expresses Chinese , It needs to be clear Character encoding ( Character set );
MySQL Default character set be called Latin ;
and Latin Yes, it doesn't support chinese Of , therefore If we want to MySQL database Can store Chinese ,
that We need to The default character set has been changed to GBK perhaps UTF-8 etc. Can store Chinese character set .
The solution to the problem
modify MySQL There are many ways of character set , Now let's introduce one " Once and for all " The way to : namely modify MySQL Configuration file for ~~
ps:
What is a configuration file ?
—— for instance Installed on the mobile phone 《 Glory of Kings 》 The game , Results found In the process of playing the game Comparison card ;
—— therefore , In the settings Some adjustments have been made : Such as Change to low image quality , Lower the resolution wait ;
—— Then although the image quality is not good , But it's very smooth , Won't card when playing ;
—— These can be adjusted Set item It's called " To configure " .
that , Be similar to This game , Usually when playing , When modifying configuration items , Are directly in the game interface Make changes ~~
This is mainly to make it easy for ordinary players to operate ~~
however , In the programming circle , Many software used , You also need to provide many configuration items ~~
Because these software are made by " The programmer " In use ~~
So those The big guy who developed the program , There is no simple and convenient interface , But directly Configuration item In a separate file , Organize in a specific format ~~
The programmer To modify the configuration , You need to change the configuration file ~~
One 、 First confirm the character set of the current database
If it's already GBK perhaps UTF-8 了 , There will be no such mistakes , It's useless to modify it ~~
We just configure UFF-8~~
-- View the character set of the current database
show variables like 'character%';
Need to see database and server part ~~
Two 、 Find the configuration file
my.ini
(1) It can be used everything Gadgets to search
however , This method is not necessarily reliable ,
Maybe some people have more than one on their computer MySQL~~
There will be more than one my.ini~~
I can't tell which one to change ~~
(2) The native method finds the configuration file
- Find the file location of the shortcut ~~
- Right click —> attribute —> Can see " The goal is "~~
- hold " The goal is " Copy out the contents , This is a MySQL Executable program path and configuration file path ~~
- hold Profile path copied , Pasting query , Find the configuration file my.ini( Of course , You need to display the extension )~~
Of course , Do not copy this path directly go in ( Very special, not recommended , Because there is no backup , In case of mistakes in the repair and modification , Then it can't be restored ):
C:\ProgramData\MySQL\MySQL Server 5.7\my.ini
【 Be careful 】 This path is only based on attribute in " The goal is " Copy from the path under , Maybe every computer is different , I don't know ~~
3、 ... and 、 Modify the configuration file
【 Be careful 】
Before modifying the configuration file , Make sure you back it up first !!!
Copy and paste a copy , Put it aside ~~
because Modification of major configurations , Be sure to back up before modifying !!!
In case you make a mistake, you can't go back ~~
Open profile :
【 Be careful 】
(1)# It starts with notes ~~
(2)ini In file , Somewhat [ ] , every last [ ] Called a selection , It is equivalent to putting a set of configurations related to functions together , Make up a selection; Equivalent to classification , Easy to manage ~~
(3)[client] It's the configuration of the client ~~[mysql] It is a configuration that may be used by both the client and the server ~~[mysqld] It is the configuration used by the server ~~
Modify the configuration file :
There are two things that need to be changed :
Specific configuration items here , It is organized by key value pairs ~~
Pay attention to the spelling of key value pairs here ~~
There should be no blank space on both sides ~~
[mysql]
default-character-set=utf8
[mysqld]
character-set-server=utf8
It's finished , Remember to save (ctrl+s),
Then you can quit ~~
Four 、 Finishing work
After modifying the configuration file , It doesn't take effect immediately ~~
You still need to do some extra work ~~
(1) restart MySQL The server !
Restart the server , Instead of closing mysql Black frame ( The client side. )~~
After reboot , Tips " Running ", The restart is successful !!!
If it's something else ( Such as Starting ......), Description restart failed !!!
The biggest reason for failure is Wrong configuration file ~~
Even if you spell one more word , It's impossible to have one more space ~~
(2) Modify the configuration file , It has no effect on the created database ~~
You must delete the old database , Rebuild the database and table ~~
5、 ... and 、 final result
Other situations that may occur
Solutions to such problems :
- The first my.ini Copy to desktop ~~
- modify ~~
- Copy back after modification , Overwrite original file ( You will be prompted to operate with administrator permission , Just click to continue )~~
边栏推荐
- OS7-资源的死锁
- 【攻防世界WEB】难度二星6分入门题(上):webshell、command_execution、xff_referer、php_rce、Web_php_include、NewsCenter
- HCIA-R&S自用笔记(14)RIP协议
- [idea] common shortcut keys of idea
- C interface basic knowledge reconstruction
- Cluster configuration and verification of MySQL Cluster (4)
- 这一次,彻底梳理各种布局问题
- QProcess类
- UDS03-根据标识符写入数据服务【ServiceID = 0x2E】
- OS09- AutoSAR OS事件机制和实例解析
猜你喜欢
UDS02-根据标识符读取数据服务【ServiceID = 0x22】
【MySQL系列】MySQL数据库基础
排错-通过LLDP信息查找环路(以H3C S5100为例)
LabVIEW cluster cannot contain input and output controls at the same time
Spoole TCP server
网络分析---并查集上做差分
[multithreading] there are several ways to create a thread pool
Midlife crisis, some thoughts on the future
顺序表与链表(顺序表)
【Harmony OS】【ARK UI】【Demo】加载动画实现
随机推荐
【开发者必看】【push kit】推送服务典型问题合集1
【HMS core】【FAQ】【Account Kit】典型问题集2
[wechat applet] choosebao - the Savior of choice difficulties
Os7 resource deadlock
【开源日记】宿舍断电自动关灯设备(二)
【MySQL系列】“一劳永逸“ 解决MySQL中 “插入中文数据“出错的问题
Hcia-r & s self use notes (13) case analysis of typical routing problems and overview of dynamic routing
【AGC】构建服务1-云函数示例
Network analysis -- making difference on the search set
UDS诊断服务的会话层和寻址方式
DCM10- 安全访问 ($27)的功能和配置【基于DaVinci Configurator Classic】
6、学习MySQL 删除数据库
检查SPF记录 宽泛的IP范围会破坏电子邮件的安全性
Samsung proposes XFORMER | surpassing mobilevit, deit, mobilenet and other models
【HMS core】【ML Kit】机器学习服务常见问题FAQ(二)
6. Learn MySQL delete database
要想上云之旅中不被“甩掉”,云服务供应商的企业生命力是关键
OS7-资源的死锁
QProcess类
2022r1 fast opening pressure vessel operation test and simulation test