Use charset utf8mb4 and collation utf8mb4_unicode_ci in MySQL and change them via phpMyAdmin or ALTER commands, also remember SET NAMES for the connection.
Charset (character set) determines which characters the database can store, and collation determines how the characters are compared and sorted. Using the wrong character set is the most common cause of Danish letters (æ, ø, å) or emojis appearing as question marks or mojibake (e.g. æ instead of æ).
Use utf8mb4 as the character set and utf8mb4_unicode_ci as the collation. utf8mb4 supports all Unicode characters, including emojis.
Change the default for the whole database (affects only new tables):
utf8mb4_unicode_ci from the dropdown menu.Change an existing table (including all its columns):
Change the database default:
ALTER DATABASE mindatabase CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Change a table and all its columns:
ALTER TABLE mintabel CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
In phpMyAdmin you can change the character set per column: select the table, click Structure, click Change next to the column, and choose a new collation in the column definition.
Generate the ALTER statements automatically:
SELECT CONCAT('ALTER TABLE `', TABLE_NAME, '` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;')
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'mindatabase' AND TABLE_TYPE = 'BASE TABLE';
Run the result in phpMyAdmin under the SQL tab or via the command line.
Database character set and connection character set are two different things. Even if your tables are correctly set to utf8mb4, characters can become corrupted in transit if the connection between your application and MySQL uses a different character set.
SET NAMES utf8mb4 sets three session variables at once:
character_set_client — what the server expects to receive from the clientcharacter_set_connection — what the server uses internally while processing queriescharacter_set_results — what the server sends back to the clientSET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;
Best practice: use the driver’s built‑in character set option instead of sending SET NAMES manually. This ensures that functions such as mysqli_real_escape_string() and PDO::quote() also use the correct character set – otherwise, in rare cases, you could open yourself to SQL injection.
Article from the support category: MySQL