Home  >  Article  >  Database  >  MySQL database saves Emoji expressions and special symbols

MySQL database saves Emoji expressions and special symbols

步履不停
步履不停Original
2019-06-21 16:09:044621browse

MySQL database saves Emoji expressions and special symbols

What is utf8mb4

  1. MySQL added this utf8mb4 encoding after version 5.5.3, mb4 is most bytes 4 means, specifically designed to be compatible with four-byte unicode. In fact, utf8mb4 is a superset of utf8

Solution:

  1. View the encoded character set:
    • SHOW VARIABLES WHERE Variable_name LIKE 'character \_set\_%' OR Variable_name LIKE 'collation%';
    • If the result is as shown in the figure below, then "the reason why the special symbols cannot be saved may be different from this article, and this article may solve it" I can’t answer your question』;
      MySQL 数据库保存 Emoji 表情及特殊符号
    • If the value field in the result is different from the picture above, please continue reading this article;
  2. Modify database encoding:
    • ALTER DATABASE database CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;;
  3. Modify data table encoding:
    • ALTER TABLE table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;;
  4. Modify the table field encoding to:
    • ALTER TABLE table CHANGE column column VARCHAR(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;;
  5. Edit the my.ini file and add or modify the following content:
    [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'
  6. RestartMysql
    • service mysqld restart
  7. View the encoded characters again Set, if the results are consistent with the above picture, you are done~

For more MySQL related technical articles, please visit Learn in the MySQL tutorial column!

The above is the detailed content of MySQL database saves Emoji expressions and special symbols. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn