存储emoji表情,修改字符集为utf8mb4

Posted 段桥123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了存储emoji表情,修改字符集为utf8mb4相关的知识,希望对你有一定的参考价值。

SHOW VARIABLES WHERE Variable_name LIKE ‘character_set_%‘ OR Variable_name LIKE ‘collation%‘;

SET character_set_client = utf8mb4;
SET character_set_connection = utf8mb4;
SET character_set_database = utf8mb4;
SET character_set_results = utf8mb4;
SET character_set_server = utf8mb4;

 

 

ALTER DATABASE 数据库名 CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

ALTER TABLE tableName CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

ALTER TABLE tableName  CHANGE `content` `content` LONGTEXT CHARACTER SET utf8mb4

 

另外my.ini(此文件在tomcat安装目录和bin在同级)文件要修改这几处:

[client]
default-character-set = utf8mb4

port=3306

default-character-set = utf8mb4
 
[mysqld]
 
 
character-set-server = utf8mb4
 
 


# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB

# Set the SQL mode to strict
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

以上是关于存储emoji表情,修改字符集为utf8mb4的主要内容,如果未能解决你的问题,请参考以下文章

mysql支持emoji表情上传

让MySQL支持Emoji表情 mysql 5.6

Mysql数据库存储emoji表情

PHP转换emoji表情为HTML字符实体

解决Emoji存储MySQL报错问题

Java在mysql中存储emoji表情