当前位置:网站首页>MySQL批量修改数据表编码及字符集为utf8mb4
MySQL批量修改数据表编码及字符集为utf8mb4
2022-07-24 05:23:00 【踩坑之路】
修改前查看:建议直接使用命令行连接数据库,最好不要使用Navicat等工具连接,不然查出的结果不准确
SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE 'collation%';
Variable_name Value
character_set_client utf8mb4
character_set_connection utf8mb4
character_set_database utf8mb4
character_set_filesystem binary
character_set_results utf8mb4
character_set_server utf8mb4
character_set_system utf8
collation_connection utf8mb4_unicode_ci
collation_database utf8mb4_unicode_ci
collation_server utf8mb4_unicode_ci
必须保证
系统变量 描述
character_set_client (客户端来源数据使用的字符集)
character_set_connection (连接层字符集)
character_set_database (当前选中数据库的默认字符集)
character_set_results (查询结果字符集)
character_set_server (默认的内部操作字符集)
这几个变量必须是utf8mb4。
修改mysql配置文件my.cnf(windows为my.ini)
找到后请在以下三部分里添加如下内容:
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
1、修改数据库编码及字符集
ALTER DATABASE db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
2、修改数据表编码及字符集
2.1 执行以下语句,生成所有需要执行的sql语句,TABLE_SCHEMA="数据库名称"对应相应的数据库名
SELECT
CONCAT("ALTER TABLE `", TABLE_NAME,"` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;")
AS target_tables
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA="数据库名称co_edu_stat"
AND TABLE_TYPE="BASE TABLE"
2.2执行完,拷贝sql语句在相应库中执行即可,数据表数量比较大时,可以先把所有sql导出为.sql文件,执行文件即可。
边栏推荐
- Public access intranet IIS website server [no public IP required]
- Custom MVC 1.0
- go语言的快速上手
- Do not rent servers, build your own personal business website (3)
- IP课(OSPF)综合实验
- IP job (2) rip
- Basic knowledge of unity and the use of some basic APIs
- Summary of common working methods (7S, SWOT analysis, PDCA cycle, smart principle, 6w2h, time management, WBS, 28 principles)
- IP笔记(6)
- Leetcode sword finger offer JZ9 dual stack implementation queue
猜你喜欢

Luckyframeweb testing platform (a full latitude free open source testing platform that supports interface automation, Web UI automation, APP automation, and distributed testing)

awk的使用

进程和计划任务管理
![[301] grotesque behavior - predictable irrationality](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[301] grotesque behavior - predictable irrationality

IP笔记(8)
![[218] what are the advantages and disadvantages of CS architecture and BS architecture and data on the server and client?](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[218] what are the advantages and disadvantages of CS architecture and BS architecture and data on the server and client?

sed命令

Use and principle of spark broadcast variable and accumulator

【217】#!/ The meaning of usr/bin/env

IP job (6)
随机推荐
剑指offer JZ10斐波那契数列
Data set and pre training model
IP notes (9)
Homework in the second week
[222] memory overflow and location
List of problems in the re disk guidance of the project
Leetcode sword finger offer JZ9 dual stack implementation queue
Modeling of XML
RAID5和LVM组合使用
Luckyframeweb testing platform (a full latitude free open source testing platform that supports interface automation, Web UI automation, APP automation, and distributed testing)
Flink time stream processing
awk的使用
一批面试题及答案_20180403最新整理
go的环境搭建和起步
Jenkins自动化无人值守运行(上/下)
力扣986.区间列表的交集
go语言常用命令和包管理
Simple three-step fast intranet penetration
Leetcode sword finger offer jz25 merges two sorted linked lists
Flink state use