Mysql实例使MySQL能够存储emoji表情字符的设置教程

发布时间:2020-05-22 发布网站:脚本之家
脚本之家收集整理的这篇文章主要介绍了Mysql实例使MySQL能够存储emoji表情字符的设置教程脚本之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

《Mysql实例使MySQL能够存储emoji表情字符的设置教程》要点:
本文介绍了Mysql实例使MySQL能够存储emoji表情字符的设置教程,希望对您有用。如果有疑问,可以联系我们。

MYSQL必读MySQL 需要支持 emoji 表情符号版本需要大于5.5.3,且字符集需要设置为utf8mb4 字符集.

MYSQL必读
utf8mb4和utf8到底有什么区别呢?原来以往的mysql的utf8一个字符最多3字节,而utf8mb4则扩展到一个字符最多能有4字节,所以能支持更多的字符集.

MYSQL必读将Mysql的编码从utf8转换成utf8mb4.

MYSQL必读需要 >= MySQL 5.5.3版本、从库也必须是5.5的了、低版本不支持这个字符集、复制报错

MYSQL必读停止MySQL Server服务

MYSQL必读修改 my.cnf或者mysql.ini

MYSQL必读
[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'

MYSQL必读重启 MySQL Server、检查字符集.

MYSQL必读查看服务器字符集设置

MYSQL必读
mysql> SHOW VARIABLES WHERE Variable_name LIKE 'character%' OR Variable_name LIKE 'collation%';
MYSQL必读
+--------------------------+--------------------+
| 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 |
+--------------------------+--------------------+

MYSQL必读查看数据库字符集

MYSQL必读
mysql> select * from SCHEMATA where SCHEMA_NAME='ttlsa';
MYSQL必读
+--------------+-------------+----------------------------+------------------------+----------+
| CATALOG_NAME | SCHEMA_NAME | DEFAULT_CHARACTER_SET_NAME | DEFAULT_COLLATION_NAME | SQL_PATH |
+--------------+-------------+----------------------------+------------------------+----------+
| def     | ttlsa   | utf8mb4          | utf8mb4_unicode_ci   | NULL   |
+--------------+-------------+----------------------------+------------------------+----------+

MYSQL必读查看表字符集

MYSQL必读
mysql> select TABLE_SCHEMA,TABLE_NAME,TABLE_COLLATION from information_schema.TABLES;
MYSQL必读
+--------------------+----------------------------------------------------+--------------------+
| TABLE_SCHEMA    | TABLE_NAME                     | TABLE_COLLATION  |
+--------------------+----------------------------------------------------+--------------------+

MYSQL必读查看列字符集

MYSQL必读
mysql> select TABLE_SCHEMA,COLUMN_NAME,COLLATION_NAME from COLUMNS;
MYSQL必读
+--------------------+----------------------------------------------------+--------------------------------------------+--------------------+
| TABLE_SCHEMA    | TABLE_NAME                     | COLUMN_NAME                | COLLATION_NAME   |
+--------------------+----------------------------------------------------+--------------------------------------------+--------------------+

MYSQL必读转换字符集语句

MYSQL必读
use information_schema;
SELECT concat("ALTER DATABASE `",table_schema,"` CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;") as _sql 
FROM `TABLES` where table_schema like "DB_NAME" group by table_schema;
SELECT concat("ALTER TABLE `","`.`",table_name,"` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;") as _sql 
FROM `TABLES` where table_schema like "DB_NAME" group by table_schema,table_name;
SELECT concat("ALTER TABLE `","` CHANGE `",column_name,"` `","` ",data_type,"(",character_maximum_length,") CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;") as _sql 
FROM `COLUMNS` where table_schema like "DB_NAME" and data_type in ('varchar');
SELECT concat("ALTER TABLE `"," CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;") as _sql 
FROM `COLUMNS` where table_schema like "DB_NAME" and data_type in ('text','tinytext','mediumtext','long

总结

以上是脚本之家为你收集整理的Mysql实例使MySQL能够存储emoji表情字符的设置教程全部内容,希望文章能够帮你解决Mysql实例使MySQL能够存储emoji表情字符的设置教程所遇到的程序开发问题。

如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您喜欢交流学习经验,点击链接加入脚本之家官方QQ群:1065694478