Three places where MySQL needs an encoding
- Column or table: the character set the data is stored in, such as
utf8mb4orlatin1. - Connection: the character set client and server talk in – set with
SET NAMES utf8mb4or in the connection settings. - File: the encoding used to read an import or write an export – in phpMyAdmin under Character set of the file.
If the three don’t match, characters break. The most common case: UTF-8 text was written over a latin1 connection into a latin1 column. The application looks fine, but phpMyAdmin and the export show é.
Before
"1","José Muñoz","Rue de l’Église 12","Genève"
After
"1","José Muñoz","Rue de l’Église 12","Genève"
Check the character sets
SHOW VARIABLES LIKE 'character_set%';shows the server and connection settings.SHOW CREATE TABLE customers;shows the character set of the table and its columns.SELECT name, HEX(name) FROM customers LIMIT 5;shows the real bytes: in autf8mb4column,C3A9is ané, whileC383C2A9is an already brokené.
Repair an export or dump
- Export the table in phpMyAdmin as SQL or CSV – or with
mysqldump --default-character-set=utf8mb4. - Drop the file into the box above. Mojibuster repairs only the broken spots; correct characters stay unchanged.
- Check the repaired spots under What changed? and download the file.
- Import it into a table with
utf8mb4and chooseutf-8as the character set in the import dialog. - Test on a copy first before replacing the real table.
The export never leaves your computer – which matters for customer data. If you use WordPress, mind the notes on serialized data on the WordPress & database page.
Fix the cause
- Create new tables with
DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci. - Set your application’s connection to
utf8mb4, in PHP for example withcharset=utf8mb4in the PDO DSN. - If UTF-8 bytes sit in a
latin1column, don’t convert it directly withCONVERT TO– that encodes them a second time and creates double-encoded text. The safe way goes through a binary type: firstMODIFY name VARBINARY(255), thenMODIFY name VARCHAR(255) CHARACTER SET utf8mb4. - If MySQL replaces characters with
?, the column or connection can’t represent them. What’s already stored that way is lost – more on question marks instead of characters.
Frequently asked questions
Why does everything look right in my application but not in phpMyAdmin?
Because application and database make the same mistake twice: the application writes UTF-8 over a latin1 connection and reads it back the same way. phpMyAdmin connects correctly and therefore shows what is really stored.
Which collation should I use?
utf8mb4_unicode_ci suits most applications; since MySQL 8, utf8mb4_0900_ai_ci is the default. The character set utf8mb4 matters more – not utf8, which can’t store emojis in MySQL.
Does this work with MariaDB too?
Yes. MariaDB handles character sets like MySQL, and the commands are the same.
How large can the dump be?
Up to 100 MB per file. Export larger databases table by table.