博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql字符集
阅读量:6087 次
发布时间:2019-06-20

本文共 3238 字,大约阅读时间需要 10 分钟。

1、查看字符集设置

mysql> show variables like 'collation_%';+----------------------+--------------------+| Variable_name        | Value              |+----------------------+--------------------+| collation_connection | utf8mb4_unicode_ci || collation_database   | utf8mb4_unicode_ci || collation_server     | utf8mb4_unicode_ci |+----------------------+--------------------+3 rows in set (0.04 sec)mysql> show variables like 'character_set_%';+--------------------------+----------------------------+| 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                       || character_sets_dir       | /app/mysql/share/charsets/ |+--------------------------+----------------------------+8 rows in set (0.00 sec)

  或者:

mysql> 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                       || character_sets_dir       | /app/mysql/share/charsets/ || collation_connection     | utf8mb4_unicode_ci         || collation_database       | utf8mb4_unicode_ci         || collation_server         | utf8mb4_unicode_ci         |+--------------------------+----------------------------+11 rows in set (0.00 sec) 
查看库的字符集:
show create database db_name;
查看表的字符集:
use db_name;show create table table_name;
查看某个表中所有列的字符集:
use db_name;show full columns from table_name;
查看mysql支持的字符集:
show charset;

2、修改字符集设置

例如修改字符集为utf8mb4,以支持emoji表情
1、配置文件修改
[client]default-character-set = utf8mb4[mysql]default-character-set = utf8mb4[mysqld]character-set-client-handshake = FALSEcharacter-set-server = utf8mb4collation-server = utf8mb4_unicode_ciinit_connect='SET NAMES utf8mb4'

2、通过MySQL命令行修改

mysql> set character_set_client=utf8mb4;mysql> set character_set_connection=utf8mb4;mysql> set character_set_database=utf8mb4;mysql> set character_set_results=utf8mb4;mysql> set character_set_server=utf8mb4;mysql> set character_set_system=utf8mb4;mysql> set collation_connection=utf8mb4;mysql> set collation_database=utf8mb4;mysql> set collation_server=utf8mb4;

3、修改库的字符集

ALTER DATABASE db_name DEFAULT CHARACTER SET utf8mb4;

4、修改表的字符集

ALTER TABLE table_name  CONVERT TO CHARACTER SET utf8mb4;

5、修改列的字符集

ALTER TABLE t_order CHANGE 列名 列名 列类型 CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

转载于:https://www.cnblogs.com/Eivll0m/p/4883554.html

你可能感兴趣的文章
codeigniter 中使用 phpexcel
查看>>
JVM监控和调优常用命令工具总结
查看>>
机器学习实战-边学边读python代码(5)
查看>>
对forEach、for-in还有es6的for-of的一些整理
查看>>
基本类型间的类型转换(数值型)
查看>>
docker 容器管理
查看>>
JavaScript 作用域
查看>>
公钥私钥RSA加密
查看>>
MVC5使用SignalR进行双向通信(1)
查看>>
手机号验证正则表达式
查看>>
通过jQuery源码学习javascript(二)
查看>>
C++基础--完善Socket C/S ,实现客户端,服务器端断开重连
查看>>
cmd 窗口配置mysql数据库
查看>>
JAVA进阶26(多线程/01)
查看>>
4.下单函数
查看>>
Shell 编程中的常用工具
查看>>
gsoap 学习 1-由wsdl文件生成h头文件
查看>>
传说中的WCF(11):会话(Session)
查看>>
First day with Java :)
查看>>
leetcode — linked-list-cycle-ii
查看>>