Home > Database > Mysql Tutorial > How to Fix the MySQL \'Incorrect string value\' Error When Storing Emojis?

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

Barbara Streisand
Release: 2024-11-23 16:38:10
Original
428 people have browsed it

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.

The above is the detailed content of How to Fix the MySQL \'Incorrect string value\' Error When Storing Emojis?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template