Incorrect String Value Error with MySQL Emojis
When attempting to store a tweet containing emojis in a MySQL table, an error may occur due to incorrect string value encoding. The error message "Incorrect string value: '\xF0\x9F\x8E\xB6\xF0\x9F...' for column 'tweet_text' at row 1." indicates that the character set in use is unable to handle the special characters.
Solution:
To resolve this issue, the database character set must be changed.
Modify MySQL Configuration (my.ini):
Open the my.ini file and add the following setting:
character-set-server=utf8mb4
Set Character Set and Collation:
Connect to MySQL and execute the following commands:
SET NAMES utf8mb4; ALTER DATABASE database_name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci;
Verify Changes:
Use the following command to confirm that the changes are applied:
SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';
After completing these steps, the MySQL database will be able to handle the storage of emojis and other special characters in UTF-8 encoding without encountering the "Incorrect string value" error.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3