存储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
[mysql]
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"