MySQL 8.0's command line client (mysql) can display and accept Unicode text—including emojis, accented characters, and non-Latin scripts—when properly configured for UTF-8 encoding. This ensures accurate data entry, correct query results, and reliable backups of multilingual content. You need MySQL Server 8.0 installed and a working command-line environment (Windows Command Prompt/PowerShell, Linux/macOS Terminal), plus basic familiarity with SQL commands. No extra software is required if MySQL is already installed.
What You'll Need
- MySQL Server 8.0 installed and running
- Access to a command-line interface (Windows CMD/PowerShell, Linux/macOS Terminal)
- Permissions to connect to the MySQL server (username/password)
- Client-side terminal that supports UTF-8 (most modern terminals do by default)
Step-by-Step
- Open your command-line interface. On Windows, launch Command Prompt or PowerShell; on macOS or Linux, open Terminal.
- Connect to MySQL 8.0 using the mysql client, explicitly specifying UTF-8 client-character-set support. Run:
mysql -u your_username -p --default-character-set=utf8mb4Replaceyour_usernamewith your MySQL account (e.g.,rootor a custom user). After pressing Enter, enter your password when prompted. The--default-character-set=utf8mb4flag is critical—it ensures the client uses full UTF-8 (4-byte) support, including emojis and rare CJK characters. - Once connected, verify the client and connection character sets by running:
SHOW VARIABLES LIKE 'character_set%';Check thatcharacter_set_client,character_set_connection, andcharacter_set_resultsall showutf8mb4. If not, proceed to step 4. - Manually set the character sets for the current session to guarantee consistency. Execute these three commands in sequence:
SET NAMES utf8mb4;
SET CHARACTER SET utf8mb4;
SET collation_connection = utf8mb4_unicode_ci;These commands align the client, connection, and result encoding to UTF-8 and ensure proper sorting/comparison rules. - Create or alter a database/table to use UTF-8MB4 as the default charset. For a new database:
CREATE DATABASE my_unicode_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;For an existing database:ALTER DATABASE my_unicode_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;For tables:ALTER TABLE my_table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;This step ensures the server stores data correctly in UTF-8MB4, not just transmits it. - Test Unicode input and display. Insert a row with multilingual content:
INSERT INTO test_table (id, content) VALUES (1, 'Café résumé 日本語 🌟');Then retrieve it:SELECT * FROM test_table;If all characters—including accented letters, Japanese, and emoji—render correctly, your setup is complete.
Common Mistakes
- Omitting
--default-character-set=utf8mb4during connection: MySQL defaults tolatin1on many systems, causing garbled text or data loss. - Using
utf8instead ofutf8mb4: MySQL'sutf8is a 3-byte subset that cannot store 4-byte characters like emojis. Always useutf8mb4. - Assuming server defaults apply: Even with correct client settings, if the database/table uses
latin1orutf8, Unicode data may be corrupted on insert. - Ignoring collation: Using
utf8_general_ciinstead ofutf8mb4_unicode_cimay lead to inconsistent sorting for accented characters or non-Latin scripts. - On Windows, using an old console (cmd.exe) with code page 437: This renders Unicode incorrectly. Switch to PowerShell or enable UTF-8 in cmd via
chcp 65001before launching mysql.
Tips
- Permanently set UTF-8MB4 on Windows: Edit or create
my.ini(in MySQL's install directory orC:\ProgramData\MySQL\MySQL Server 8.0\), and under[mysql], add:default-character-set=utf8mb4. - On Linux/macOS, edit
/etc/mysql/my.cnfor~/.my.cnf, adding under[mysql]:default-character-set = utf8mb4. - When scripting, include
SET NAMES utf8mb4;at the top of SQL files to avoid encoding drift across sessions. - Verify table columns explicitly use
utf8mb4with:SHOW FULL COLUMNS FROM your_table;and inspect theCollationandCharacter Setcolumns. - Use
mysql --print-defaultsto confirm which config files the client reads, helping diagnose persistent encoding issues. - For backups, use
mysqldump --default-character-set=utf8mb4to preserve Unicode in dumps.
Troubleshooting
- Garbled or ? characters in output: First, confirm your terminal supports UTF-8. On Linux/macOS, run
localeand check forUTF-8. On Windows, runchcp 65001before mysql. Then re-runSHOW VARIABLES LIKE 'character_set%'—ifcharacter_set_clientisn'tutf8mb4, reconnect with--default-character-set=utf8mb4. - "Incorrect string value" error on insert: This means the target column or table isn't
utf8mb4. Verify withSHOW CREATE TABLE your_table;and convert the table or column:ALTER TABLE your_table MODIFY column_name VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; - Emoji appear as squares or placeholders: Your font may lack emoji support. Switch to a Unicode font (e.g., Segoe UI Emoji on Windows, Apple Color Emoji on macOS). Also ensure you're using
utf8mb4(notutf8) and the column type isutf8mb4. - Connection resets after setting character sets: Some MySQL versions reject mismatched client/server collations. Use
utf8mb4_unicode_ci(not_binor region-specific) unless you have strict binary sorting needs. - Still failing after all steps: Restart the MySQL service to reload config files. Then check the server's error log (often in
/var/log/mysql/error.logor MySQL data directory) for character-set-related warnings.
Frequently Asked Questions
Does MySQL 8.0 support full Unicode including emojis?
Yes—using theutf8mb4 character set and collation. MySQL's legacy utf8 only supports 3-byte characters and cannot store emojis or some rare CJK symbols.
Can I use Unicode without changing existing databases?
Only for new inserts if the client sends UTF-8 and the server accepts it. However, existing data in non-UTF-8 tables will remain misencoded. Always convert tables withALTER TABLE ... CONVERT TO CHARACTER SET utf8mb4 for full reliability.
Why does my terminal show question marks even after setting utf8mb4?
The terminal itself must be configured for UTF-8. On Windows, use PowerShell or runchcp 65001 in cmd. On Linux, ensure LANG includes UTF-8 (e.g., en_US.UTF-8).
Is it safe to change a database to utf8mb4 after data exists?
Yes—if done correctly. RunALTER DATABASE ... and ALTER TABLE ... CONVERT TO CHARACTER SET utf8mb4. Back up first, as this rebuilds tables. The conversion preserves data but may change sort order for some characters.
Do I need to set character sets in every session?
No—if you configuredefault-character-set=utf8mb4 in your MySQL client config file (my.cnf or my.ini), it applies automatically to all new connections.
Can I mix utf8mb4 and latin1 tables in the same database?
Yes, but comparisons across tables/columns may fail or return unexpected results. Standardize onutf8mb4 for all tables to avoid encoding conflicts in joins or unions.