Emoji expression Character insertion configuration

Source: Internet
Author: User

Recently done in the project, in insert?? The character times is wrong.

13661366stringvalue‘\xF0\x9D\x8C\x86‘for‘vl‘at1

After a few hours of struggling to resolve it off ~ ~ Just transfer UTF8 to utf8mb4.

This problem is not so difficult, it took a long time to solve the main or because the configuration of MySQL is not very clear, fortunately the use of the database version is 5.5.39, because lucky enough in the version of MySQL 5.5.3 (released in early 2010), Just as MySQL supports the UTF8MB4 character set.

Specific UTF8 and utf8mb4 differences, you can refer to the HTTPS://MATHIASBYNENS.BE/NOTES/MYSQL-UTF8MB4

Below the corresponding solution to paste out, thank Daniel Everywhere Ah ~ ~

To deal with this situation must be changed/etc/mysql/my.cnf file, the location of the specific files according to their own configuration to find it.

Let's look at the existing character set of MySQL Server.

This is my current database configuration.

Next we add the following configuration in the MY.CNF

[client]default-character-set=utf8mb4[server]character_set_server=utf8mb4

Post-Configuration scenarios

You can see that the client, connection, database, result, and server in the configuration are UTF8MB4. In fact, the completion of the 90%, as long as the verification of the know.

Very good, no error, the next query, you can see if you can display the normal

This step is also correct!
In this way, we have completed the configuration of the database, but it is also important to note that the current operation of the database, data tables, fields are also required to support the UTF8MB4

# for each database: ALTER DATABASE database_name CHARACTER SET = utf8mb4 COLLATE = utf8mb4 _unicode_ci;# for each table: ALTER TABLE table_name CONVERT  to CHARACTER SET utf8mb4  COLLATE utf8mb4_unicode_ci;# for each column: ALTER TABLE table_name Change column_name column_name VARCHAR(191)  CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

All done!

In the process of making this change, I actually used both Mysql-workbench and MySQL to access it, but strangely

SHOW VARIABLES LIKE ‘%character%‘

The MySQL command shows the configuration of the local database, but in the mysql-workbench is not, quite depressed ah ~ ~

You can see that the client, connection, and so on have not been changed to UTF8MB4, do not know whether Mysql-workbench has other configurations, unfortunately has not found a specific configuration, however, as a temporary solution, you can use the following command to handle

SET NAMES utf8mb4

This feeling is quite convenient ah, all of a sudden to get rid of, but not lasting ~ ~

~ ~ Oh, give this kind of plan temporarily, know the reason of the handsome girl also hope to give a hint ^_^

Emoji expression Character insertion configuration

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.