Allow Mysql to store emoji emoticons in the settings tutorial _mysql

Source: Internet
Author: User

MySQL needs to support emoji emoticons version requires greater than 5.5.3, and the character set needs to be set to the UTF8MB4 character set.


What's the difference between utf8mb4 and UTF8? The original MySQL UTF8 a character up to 3 bytes, while UTF8MB4 expands to a character up to 4 bytes, so it can support more character sets.

Converts the MySQL encoding from UTF8 to UTF8MB4.

Need to >= MySQL 5.5.3 version, from the library must also be 5.5, the lower version does not support this character set, replication error

Stop the MySQL Server service

Modify MY.CNF or Mysql.ini

[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 '

Reboot the MySQL Server and check the character set.

View server character Set settings

Mysql> show VARIABLES WHERE variable_name like ' character% ' 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        |
| collation_connection | utf8mb4_unicode_ci | |
collation_database    | Utf8mb4_unicode_ci |
| Collation_server     | utf8mb4_unicode_ci
| +--------------------------+--------------------+

View the database character set

Mysql> SELECT * from schemata where schema_name= ' Ttlsa ';
+--------------+-------------+----------------------------+------------------------+----------+
| Catalog_name | schema_name | Default_character_set_name | Default_collation_name | Sql_path |
+--------------+-------------+----------------------------+------------------------+----------+
| def     | Ttlsa   | utf8mb4 |          UTF8MB4_UNICODE_CI   | NULL   |
+--------------+-------------+----------------------------+------------------------+----------+

View Table Character Set

Mysql> Select Table_schema,table_name,table_collation from INFORMATION_SCHEMA. TABLES;
+--------------------+----------------------------------------------------+--------------------+
| Table_schema    | TABLE_NAME                     | Table_collation  |
+--------------------+----------------------------------------------------+--------------------+

View column Character sets

Mysql> select Table_schema,table_name,column_name,collation_name from COLUMNS;
+--------------------+----------------------------------------------------+------------------------------------ --------+--------------------+
| Table_schema    | TABLE_NAME                     | column_name                | Collation_name   |
+--------------------+----------------------------------------------------+------------------------------------ --------+--------------------+

Converting character Set statements

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_schema, "'. '", table_name, "' CONVERT to CHARACTER SET utf8mb4 COLLATE CI; ")
As _sql from ' TABLES ' where Table_schema like "Db_name" GROUP by TABLE_SCHEMA, TABLE_NAME; SELECT concat ("ALTER TABLE", Table_schema, "'.", TABLE_NAME, "change", column_name, "" ", 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", Table_schema, "'.", TABLE_NAME, "change", column_name, "" ", Column_name," "", data_type , "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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.