当前位置:网站首页>Solve the problem that MySQL cannot insert Chinese data
Solve the problem that MySQL cannot insert Chinese data
2022-08-01 17:43:00 【Wei Wei Qin Qin】
目录
1️⃣When creating a database, set the character set toutf8
我们使用MySQLMay encounter the situation of adding Chinese error,如下.
报错:illegal character value 放入 ‘name’ Why can't I deposit in Chinese??
原因:
for the current database 来说,Internal storage of Chinese is required to specify the corresponding Chinese encoding method!
The database default character set,是“拉丁文”,不能存中文.
我们在控制台输入,The following line of command,查看数据库字符集.
show variables like '%char%';
我们看 character_set_database This line corresponds to Value的是 latinl,而 latinl 是拉丁文,是不支持中文的.
Now we know why the database cannot store Chinese,So what should I do to make the database insert Chinese??我们接着往下看
具体解决方法:
I mainly introduce two methods,一种简单的,一个比较复杂,but it is essentially modifying 数据库 字符编码
1️⃣When creating a database, set the character set toutf8
We set to support Chinese character set when we created the databaseutf8,如下
create database 数据库名 character set utf8;
设置完后,We can change the database to insert Chinese.
When we look at the database again,We will find that we set the database character set to change,but when we use other database,Its character set is still latinl.
这种方法,Simple but requires manual setup every time,Is there a way to do it once and for all.
Let's look at method two.
2️⃣修改数据库配置文件(比较麻烦)
我们可以修改MySQL的配置文件,His character is modified toutf8,This way you don't have to manually set up the database again..
什么是配置文件:
很多程序,Internal support for a variety of“模式”,The current program can be adjusted,let him apply that pattern.
因此就可以借助“开关”来切换模式!Software switches usually use a“图形化界面”,但是对于 MySQL Special software such as programmers generally does not have a corresponding graphical interface to indicate the switch..Only through a special file,to save these switches.这个文件就是 “配置文件”.
So if the programmer wants to adjust these switches,to manually modify this file.
1、找到MySQL的配置文件
The configuration file path is different on each computer,我们可以‘服务’to find its path to
然后在服务中,找到MySQL,find executable path in general,复制下来.
大家可以像我一样,Copy the path and put it in the drawing for easy viewing.如下图,画红线的就是MySQL配置文件路径,Then we look for the configuration file according to the path
在查找过程中 You can't find it ProgramData 文件,The file is hidden,When we click on Show Hidden Items, it will appear.
2、修改文件
找到 后缀为 .ini 文件后,We can open it in Notepad for editing.
注意:
Everyone before editing,一定要先备份!!!
Such files are very critical,Once corrected,mysql 就启动不了了!!
如何备份:We directly select the file,Assign and paste.
First find in the file[mysql],add below default-character-set=utf8
注意:=两侧不要有空格
然后找到[mysqld],把 In the picture below, the red box is changed to character-set-server=utf8 ,Exit and save after making changes
3、重启MySQL服务器(重要)
MySQLis a client server program,我们要重启MySQL服务器.we find in the serviceMySQL之后,Right click to restart.重启后MySQL显示‘正在运行’,即重启成功!
注意:restart isMySQL服务器,不是MySQL客户端
如果启动失败,Maybe the configuration file is wrong,You can go back and check if there is a spelling error or a lot of spaces.
到这里就配置成功了,We can try to build a library and insert Chinese
The configuration just now,Affects new libraries.old library,still the previous encoding!!! Remember to delete the library,重新建库
边栏推荐
猜你喜欢
一加OnePlus 10RT出现在Geekbench上 产品发布似乎也已临近
OnePlus 10RT appears on Geekbench, product launch also seems to be approaching
RecSys'22|CARCA: Cross-Attention-Aware Context and Attribute Recommendations
直播系统聊天技术(八):vivo直播系统中IM消息模块的架构实践
【Day_12 0507】查找组成一个偶数最接近的两个素数
史上最全的Redis基础+进阶项目实战总结笔记
RecSys'22|CARCA:交叉注意力感知上下文和属性进行推荐
【报错】Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘concat‘)
食品安全 | 新鲜食品vs速食食品,哪一种是你的菜?
8月微软技术课程,欢迎参与
随机推荐
XAML WPF item groupBox control
ROS2支持技术:DDS简述
今年最火爆的词:商业分析,看这一篇就够了!
三维空间中点的插值
一加OnePlus 10RT出现在Geekbench上 产品发布似乎也已临近
DBPack SQL Tracing 功能及数据加密功能详解
Flask框架实战
变量交换;复合赋值;增递减运算符
RecSys'22|CARCA:交叉注意力感知上下文和属性进行推荐
QLineEdit learning and use
深入分析类加载器
SQL的索引详细介绍
基于BiGRU和GAN的数据生成方法
创造建材数字转型新视界,中建材如何多边赋能集团业务快速发展
指针和解引用
自定义注解实现日志打印时屏蔽特定字段不打印
解决MySQL插入不了中文数据问题
我在启牛开户安全吗?谁能告诉我开不靠谱?
QT_Event class
Topology Parts Disassembly 3D Visualization Solution