Configure the insert of emoji characters and insert of emoji characters
An error is reported when a character is inserted in a recently created Project.
ERROR 1366: 1366: Incorrect string value: '\xF0\x9D\x8C\x86' for column 'vl' at row 1
After struggling for several hours, I solved it ~~ You only need to convert utf8 to utf8mb4.
This problem is actually not that difficult. It took a long time to solve the problem mainly because the MySQL configuration is not very clear. Fortunately, the database version used is 5.5.39, fortunately, MySQL 5.5.3 (released in early 2010) supports the utf8mb4 character set.
Specific utf8 and utf8mb4 difference, can refer to the https://mathiasbynens.be/notes/mysql-utf8mb4
Next, I will post the corresponding solution. Thanks to Daniel for being everywhere ~~
To deal with such a situation, you must change the/etc/mysql/my. cnf file. Locate the specific file based on your configuration.
Let's check the current character set of MySQL Server.
This is my current Database Configuration
Next, add the following configuration in my. cnf:
[client]default-character-set=utf8mb4[server]character_set_server=utf8mb4
After configuration
We can see that the client, connection, database, result, and server in the configuration are all utf8mb4. In fact, 90% is completed here, and you only need to verify it.
Good. No error is reported. perform the following query to check whether the display is normal.
This step is correct!
In this way, we have completed the database configuration. However, we must note that the current database, data table, and field must also support 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 mysql-workbench and mysql for access at the same time, But the strange thing is that
SHOW VARIABLES LIKE '%character%'
The configuration of the local database is displayed under the mysql command, but not in mysql-workbench. It is quite depressing ~~
We can see that the client, connection, and so on are not changed to utf8mb4. I don't know if there are other configurations in mysql-workbench. Unfortunately, no specific configuration scheme has been found yet, as a temporary solution, you can use the following command to handle
SET NAMES utf8mb4
This is quite convenient, but it is not persistent ~~
~~ Oh, I have provided this scheme for the time being. The handsome girl who knows the reason also hopes to give a prompt.