当前位置:网站首页>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文件,执行文件即可。
边栏推荐
- XML parsing
- IA笔记 1
- Getting started with Lunix commands - user and file permissions (Chmod details)
- IP job (1)
- Do not rent servers, build your own personal business website (1)
- Leetcode sword finger offer jz23: the entry node of the link in the linked list
- [218] what are the advantages and disadvantages of CS architecture and BS architecture and data on the server and client?
- How to build a website full of ritual sense and publish it on the public website 2-2
- 【222】内存溢出及定位
- mysql 忘记退出直接关闭窗口现在要删除整个文件夹如何删除
猜你喜欢

awk的使用

IP笔记(9)

一批面试题及答案_20180403最新整理

Polkadot | interprets how liberty plan, which subverts traditional social media, will be launched in Poka

leetcode 不用加减乘除算加法 || 二进制中1的个数

IP lesson summary (3)

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

IP notes (6)

RESTful API介绍

Summary of common working methods (7S, SWOT analysis, PDCA cycle, smart principle, 6w2h, time management, WBS, 28 principles)
随机推荐
Sword finger offer jz10 Fibonacci sequence
Dameng database_ Small matters needing attention during use
Mysql database - SQL summary (remember to pay attention to me! Come on in China!)
Playing RTSP video stream on webpage
Do not rent servers, build your own personal business website (4)
IP course (OSPF) comprehensive experiment
MySQL forgot to exit and close the window directly. How to delete the entire folder now
Ia class summary (1)
Public access intranet IIS website server [no public IP required]
General paging 2.0
Pycharm set code template
Flink function (1): rich function
leetcode剑指offer JZ42 连续子数组的最大和
Remember 20 classic interview questions of performance test in three minutes
MySQL从基础到入门到高可用
三分钟记住20道性能测试经典面试题
常用工作方法总结(7S、SWOT分析、PDCA循环、SMART原则、6W2H、时间管理、WBS、二八原则)
Modeling of XML
【301】怪诞行为学-可预测的非理性
力扣986.区间列表的交集