Home >Database >Mysql Tutorial >How to Fix MySQL\'s \'Incorrect String Value\' Error When Using Emojis?

How to Fix MySQL\'s \'Incorrect String Value\' Error When Using Emojis?

Susan Sarandon
Susan SarandonOriginal
2024-12-09 03:04:14738browse

How to Fix MySQL's

Troubleshooting "Incorrect String Value" Error in MYSQL with Emojis

While attempting to store a tweet containing emojis in a MYSQL table with utf8mb4 encoding, you may encounter an "Incorrect string value" error. This occurs because the emojis are encoded using a different UTF-8 sequence than expected.

Solution:

The solution involves modifying MYSQL settings and running specific commands to ensure proper handling of multibyte character sets, including emojis.

  1. Update the character set in my.ini to utf8mb4.
  2. Execute the following commands in the MYSQL client:

    • SET NAMES utf8mb4;
    • ALTER DATABASE CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci;
  3. Verify the changes with the command:

    • SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE 'collation%';

These steps ensure that MYSQL uses the correct character set and collation for handling UTF-8 characters, including emojis. After making these changes, you should be able to store the tweet with emoji characters successfully in your table.

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

Statement:
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