当前位置:网站首页>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脚本来批量执行 直接上代码
边栏推荐
猜你喜欢
随机推荐
ALV report learning summary
2022-07-28
扫码预约 | 观看Apache Linkis数据处理实践以及计算治理能力
解析List接口中的常用的被实现子类重写的方法
GNN教程:图神经网络基础知识!
ShardingSphere-proxy +PostgreSQL implements read-write separation (static strategy)
LeetCode 622 设计循环队列[数组 队列] HERODING的LeetCode之路
笑话:如果你在河边等待得足够久,你会看到你的敌人的尸体漂过,是怎么翻译出来的?
VMware虚拟机无法上网
Thread线程类基本使用(下)
新增指令 v-memo
ALV概念讲解
基于“无依赖绝对定位”实现的圣杯三栏布局
es 读流程源码解析
基本语法(三)
unittest自动化测试框架总结
Leetcode刷题——单调栈问题(739每日温度问题、496下一个更大元素I、503下一个更大元素 II)
ALV报表学习总结
PG 之 SQL执行计划
EasyExcel实现动态列解析和存表









