当前位置: 首页 > news >正文

MySQL 8.0字符集校正

MySQL升级为8.0版本时,之前版本的字符集往往是不同的,需要校正。

执行下面的三个SQL语句的查询结果,可以从库、表、列三个层面对字符集进行校正。

  • select concat('alter database ', schema_name, ' default character set utf8mb4 collate utf8mb4_general_ci;')from information_schema.schematawhere schema_name not in ('sys', 'mysql', 'performance_schema', 'information_schema')and (lower(default_collation_name) != 'utf8mb4_general_ci' or lower(default_character_set_name) != 'utf8mb4');
    
  • select concat('alter table ', table_schema, '.', table_name,' default character set utf8mb4 collate = utf8mb4_general_ci;')from information_schema.tableswhere table_schema not in ('sys', 'mysql', 'performance_schema', 'information_schema')and table_type = 'BASE TABLE'and lower(table_collation) != 'utf8mb4_general_ci';
    
  • set group_concat_max_len = 10240;select concat(c1, c2, ';')from (select c1, group_concat(c2) c2from (select concat('alter table ', t1.table_schema, '.', t1.table_name) c1,concat(' modify ', '`', t1.column_name, '` ', t1.data_type,if(t1.data_type in ('varchar', 'char'), concat('(', t1.character_maximum_length, ')'),''),if(t1.column_default != '', concat(' default \'', t1.column_default, '\''), ''),' collate utf8mb4_general_ci',if(t1.is_nullable = 'NO', ' not null', ' null'), ' comment ', '''', t1.column_comment,'''')                                                c2from information_schema.columns t1,information_schema.tables t2where t1.table_schema = t2.table_schemaand t1.table_name = t2.table_nameand t2.table_type = 'BASE TABLE'and (lower(t1.collation_name) != 'utf8mb4_general_ci' or lower(t1.character_set_name) != 'utf8mb4')and t1.table_schema not in ('sys', 'mysql', 'performance_schema', 'information_schema')) t1group by c1) t;
    
http://www.lryc.cn/news/143254.html

相关文章:

  • 软考:中级软件设计师:数据库恢复与备份,故障与恢复,反规范化
  • Unbutu系统-Docker安装、JDK环境配置,Docker常用指令、Docker安装MySQL、Redis、Tomcat、Nginx,前端后分离项目部署
  • Python绘图系统10:在父组件中使用子组件的函数
  • 【Linux的成长史】Linux的发展史
  • OLED透明屏是什么?什么叫做OLED透明屏的原屏?
  • Redis 持久化的手段有哪些 ?RDB 和 AOF 有什么区别 ?
  • 【Vue】vue2预览显示quill富文本内容,vue-quill-editor回显页面,v-html回显富文本内容
  • 华纳云:ubuntu下nginx服务器如何配置
  • PTP时间同步例程
  • 【ES6】ES6遍历属性的方法
  • 【Web系列二十四】使用JPA简化持久层接口开发
  • Flink流批一体计算(16):PyFlink DataStream API
  • 软考高级系统架构设计师系列论文九十三:论计算机网络的安全性设计
  • 山西电力市场日前价格预测【2023-08-29】
  • 计算机毕设 基于深度学习的人脸专注度检测计算系统 - opencv python cnn
  • ES 7.6 - APi基础操作篇
  • 【Go 基础篇】Go语言循环结构:实现重复执行与迭代控制
  • RabbitMQ笔记-RabbitMQ基本术语
  • Git向远程仓库与推送以及拉取远程仓库
  • PostgreSQL+SSL链路测试
  • 服务器(容器)开发指南——code-server
  • C++贪吃蛇(控制台版)
  • Java之字符串实践
  • BM20 数组中的逆序对
  • 高德猎鹰轨迹查询相关接口
  • 整理总结新手开始抖音小店经营:常见问题及解决办法
  • 4-1-netty
  • hive 动态分区-动态分区数量太多也会导致效率下降只设置非严格模式也能执行动态分区
  • java八股文面试[JVM]——JVM调优
  • FairyGUI-Unity 异形屏适配