当前位置:网站首页>Solve the docker mysql can't write Chinese
Solve the docker mysql can't write Chinese
2022-08-02 23:04:00 【Rambutan】
携手创作,共同成长!这是我参与「掘金日新计划 · 8 月更文挑战」的第1天,点击查看活动详情
问题描述
The content of the front-end page is entered in Chinese,or generated during executionlogThe information is in Chinese,Will report database-related coding errors. 经查看docker 生成的mysqlThe database coded character set is by defaultlatin, 不是utf-8,The database encoding character set needs to be modified,In addition to modifying the encoding of the database,Also need to modify the data table,The coded character set for the fields of the data table
关于mysqlCharacter set knowledge
我们创建表的时候,有一个charset字段,同时还会有一个collate字段. The following text is from the Internet,讲的很不错.
COLLATE
通常是和数据编码(CHARSET
)相关的,一般来说每种CHARSET
都有多种它所支持的COLLATE
,并且每种CHARSET
都指定一种COLLATE
为默认值.例如Latin1
编码的默认COLLATE
为latin1_swedish_ci
,GBK
编码的默认COLLATE
为gbk_chinese_ci
,utf8mb4
编码的默认值为utf8mb4_general_ci
.
mysql中有utf8
和utf8mb4
两种编码,在mysql中请大家忘记**utf8**
,永远使用**utf8mb4**
.这是mysql的一个遗留问题,mysql中的utf8
最多只能支持3bytes长度的字符编码,对于一些需要占据4bytes的文字,mysql的utf8
就不支持了,要使用utf8mb4
才行.
很多COLLATE
都带有_ci
字样,这是Case Insensitive的缩写,即大小写无关,也就是说"A"和"a"They are treated equally when sorting and comparing.selection * from table1 where field1="a"
同样可以把field1为"A"value selected.与此同时,对于那些_cs
后缀的COLLATE
,则是Case Sensitive,i.e. case sensitive
登录docker mysql
There are several ways to log in
一种通过docker 容器命令行
Find the command line button as shown in the figure,Click to enter the command line terminal Enter login in the terminalmysql的命令: mysql -uname -ppwd
A through database management software
我用的是dbeaver, 注意连接数据库的port要和docker里的port端口保持一致
修改数据库编码
在这里,我直接在dbeaver执行如下语句 The first line is the displaymysqlThe character set setting for the current database The rest of the lines are all setting the character set toutf-8 执行成功后,The following can be executed againshowThe statement verifies the following.
show variables like 'character%';
set character_set_database =utf8;
set character_set_results =utf8;
set character_set_server =utf8;
set character_set_system =binary;
SET collation_server = utf8_general_ci;
SET collation_database = utf8_general_ci;
复制代码
Modify data tables and data table fields
核心sql语句如下:
'alter table tableName character set utf8mb4;修改数据表,To specify a specific data table name
show create tableName ;验证是否修改成功
alter table tableName convert to character set utf8 collate utf8_general_ci; 修改数据表字段
Batch modify data tables and data table fields
Because there are more data sheets,就写了一个python脚本来批量执行 直接上代码
边栏推荐
- MaxCompute 近期发布上线的版本的 SQL 引擎新功能参数化视图有什么优势?
- Introduction of uncommon interfaces of openlayers
- 实现客户服务自助,打造产品知识库
- 实现fashion_minst服装图像分类
- LeetCode 622 设计循环队列[数组 队列] HERODING的LeetCode之路
- AI Scientist: Automatically discover hidden state variables of physical systems
- VMware虚拟机无法上网
- 软考 ----- UML设计与分析(下)
- golang 源码分析:uber-go/ratelimit
- 译出我精彩 | 7月墨力翻译计划获奖名单公布
猜你喜欢
随机推荐
APP自动化uiautomator2获取toast
ECCV 2022 | 通往数据高效的Transformer目标检测器
磁盘分区的知识
如何解决图像分类中的类别不均衡问题?不妨试试分开学习表征和分类器
The so-called fighting skill again gao also afraid of the chopper - partition, depots, table, and the merits of the distributed
es DELETE index 源码分析
golang刷leetcode 经典(10) tire树与ac自动机
Parse the commonly used methods in the List interface that are overridden by subclasses
日志框架学习
GNN教程:图神经网络基础知识!
MaxCompute 的SQL 引擎参数化视图具体有哪些增强功能?
技术分享 | Apache Linkis 快速集成网页IDE工具 Scriptis
[AnXun cup 2019] easy_web
成为黑客不得不学的语言,看完觉得你们还可吗?
MySQL安装时一直卡在starting server
PyTorch分布式backends
Cannot find declaration to go to
【LeetCode】1161. 最大层内元素和
golang 源码分析:uber-go/ratelimit
力扣每日一题-第46天-344. 反转字符串