My Question
How can I store or convert emojis and french accents and other special non-ascii characters in a MySQL database?
The Problem
Within the wp_posts
table of my MySQL database called local
, some characters in the content of the post_content
column are emojis or french accent characters like ë
.
When I view the field content in Adminer, the emojis are not rendered properly but the special french accent characters are:
What I've Tried
UPDATE wp_posts SET post_content = CONVERT(CAST(CONVERT(post_content USING latin1) AS BINARY) USING utf8)
^This SQL command converts most special characters but it totally nullifies (deletes all content) for the rows that have emojis or french characters.
UPDATE wp_posts SET post_content = CAST(CAST(CONVERT(post_content USING latin1) AS binary) AS CHAR)
^This SQL command successfully converts all emojis when I only run it on rows that include emojis:
however, when I try to run this on the whole table, I get the following error:
Error in query (1366): Incorrect string value: '\xEBlle B...' for column 'post_content'
The command trips up once it gets to a french accent character. The \xEBlle
is the ë
from Noëlle
.
My Setup
Local | v6.1.5+5536 |
Adminer | v4.8.1 |
MySQL | v8.0.16 |
PHP | v7.3.5 |
Database (local ) Collation |
utf8mb4_general_ci |
Table (wp_posts ) Collation |
utf8mb4_general_ci |
Column (post_content ) Collation |
utf8mb4_general_ci |
Column (post_content ) Type |
longtext |