当前位置:网站首页>关于在cmd中MySQL不能插中文数据的原因
关于在cmd中MySQL不能插中文数据的原因
2022-06-28 08:06:00 【庸懒】
下面是本人参考的博客的链接,本文只是当作笔记记载,如果需要看详细过程建议移步原博客哦
https://www.cnblogs.com/1102whw/p/7815466.html
https://www.iteye.com/blog/lwjlaser-1013071
最近在学习数据库,但是用cmd操作的时候碰见一个问题,就是我使用插入语句的时候一直报错,其他语句没有任何问题,而且错误就出在中文数据上。
这是在power shell上运行的结果,很明显是中文的问题,所以我就查了下发现是命令行编码格式的问题,cmd默认是gbk.于是我将cmd的编码格式改成了utf-8,这个方法在我博客有。但是问题并没有解决。


可以看到我的cmd已经换成了utf-8的格式但是使用插入语句的时候依然有问题。正当我百思不得其解的时候我发现了一个大佬的博客,完美的解决了我的问题,最后我会放出地址,这里先做下笔记。
1.查看数据库安装目录下的my.ini文件,查看红框中是否是是utf-8的格式,这里可以看到我的是没有问题的。

2.使用下面的命令查看自己数据库的编码格式
$ show variables like ‘%char%’;

可以看到我这里全部都是utf-8的格式,按理来说应该大功告成,可是我在执行insert语句的时候报了之前的错,原因就是这万恶的cmd!!!虽然我将cmd的编码格式改成了utf-8但是cmd输入的中文还是gbk,所以输入的中文识别不了,我真是日了旺财了。
3.因为cmd输入编码无法更改,所以只能退而求其次将我们的编码格式改成gbk,使用下面的语句就可以了
$ set names gbk;
这里在说一下数据库字符集的东西,其中与服务器端相关:database、server、system(永远无法修改,就是utf-8);与客户端相关:connection、client、results

虽然可以解决问题但是我个人并不推荐,因为gbk只能显示中文,万一要是整个日文韩文呢?所以咱绝不将就,就必须得用utf-8,所以我建议你使用navicat,好用又强大,用了都说好。
边栏推荐
- Online WPS tool
- Software testing and quality final review
- Activity implicit jump
- [JS] - [throttling and anti shake function]
- Software design of power control board
- HJ成绩排序
- Jenkins' common build trigger and hook services (V)
- HJ base conversion
- 【js】-【DFS、BFS应用】-学习笔记
- MySQL implements transaction persistence using redo logs
猜你喜欢

Prometheus + grafana + MySQL master-slave replication + host monitoring

NLP sequence can completely simulate human brain intelligence

Kubernetes理论基础

Prometheus service discovery

asp. Net error "/" server error in the application. String or binary data would be truncated. The statement...

Trigonometric transformation formula

Software design of resistance test board

22/02/14 study notes

Redis cerebral fissure

Jenkins' common build trigger and hook services (V)
随机推荐
Leetcode摆动序列系列
cuda和cudnn和tensorrt的理解
Section VII starting principle and configuration of zynq
asp. Net registration page
[JS] - [throttling and anti shake function]
asp. Net to search products and realize paging function
十大券商注册开户靠谱吗?安全吗?
flex布局
B_QuRT_User_Guide(30)
ROS notes (09) - query and setting of parameters
Today's notes 22/1/7
SQL master-slave replication setup
Design of DSP image data stream
How to insert a single quotation mark into a table as a data type in Oracle pl/sql
Disposition Flex
Localization SoC development plan
NLP sequence can completely simulate human brain intelligence
How to use redis to solve concurrency problems
ROS 笔记(08)— 服务数据的定义与使用
MySQL installation and environment variable configuration