"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Fix the MySQL \"Incorrect string value\" Error When Storing Emojis?

How to Fix the MySQL \"Incorrect string value\" Error When Storing Emojis?

Published on 2024-12-22
Browse:246

How to Fix the MySQL \

Resolving the "Incorrect string value" Error in MySQL for Emoji Storage

When storing tweets containing emojis like "🎶," users may encounter an error stating "Incorrect string value..." This error is caused by incompatible character encodings.

To resolve this issue, the character sets of the database and the table where the tweets are stored need to be configured to support Unicode characters. Here are the steps to follow:

  1. Modify the MySQL Configuration File:

    • Open the MySQL configuration file (usually named my.ini or my.cnf) in a text editor.
    • Find the [mysqld] section and add or modify the following lines:

      • character_set_client=utf8mb4
      • character_set_server=utf8mb4
      • collation_server=utf8mb4_general_ci
  2. Change Database and Table Character Sets:

    • Connect to MySQL and run the following commands:

      • SET NAMES utf8mb4;
      • ALTER DATABASE CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci;
      • ALTER TABLE CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci;
  3. Verify the Changes:

    • Run the following command to confirm the character set and collation settings:

      • SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';

After making these changes, the MySQL database should be able to store tweets with emojis without encountering the "Incorrect string value" error.

Latest tutorial More>

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