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

  1. Open your command-line interface. On Windows, launch Command Prompt or PowerShell; on macOS or Linux, open Terminal.
  2. 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=utf8mb4 Replace your_username with your MySQL account (e.g., root or a custom user). After pressing Enter, enter your password when prompted. The --default-character-set=utf8mb4 flag is critical—it ensures the client uses full UTF-8 (4-byte) support, including emojis and rare CJK characters.
  3. Once connected, verify the client and connection character sets by running: SHOW VARIABLES LIKE 'character_set%'; Check that character_set_client, character_set_connection, and character_set_results all show utf8mb4. If not, proceed to step 4.
  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.
  5. 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.
  6. 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=utf8mb4 during connection: MySQL defaults to latin1 on many systems, causing garbled text or data loss.
  • Using utf8 instead of utf8mb4: MySQL's utf8 is a 3-byte subset that cannot store 4-byte characters like emojis. Always use utf8mb4.
  • Assuming server defaults apply: Even with correct client settings, if the database/table uses latin1 or utf8, Unicode data may be corrupted on insert.
  • Ignoring collation: Using utf8_general_ci instead of utf8mb4_unicode_ci may 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 65001 before launching mysql.

Tips

  • Permanently set UTF-8MB4 on Windows: Edit or create my.ini (in MySQL's install directory or C:\ProgramData\MySQL\MySQL Server 8.0\), and under [mysql], add: default-character-set=utf8mb4.
  • On Linux/macOS, edit /etc/mysql/my.cnf or ~/.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 utf8mb4 with: SHOW FULL COLUMNS FROM your_table; and inspect the Collation and Character Set columns.
  • Use mysql --print-defaults to confirm which config files the client reads, helping diagnose persistent encoding issues.
  • For backups, use mysqldump --default-character-set=utf8mb4 to preserve Unicode in dumps.

Troubleshooting

  • Garbled or ? characters in output: First, confirm your terminal supports UTF-8. On Linux/macOS, run locale and check for UTF-8. On Windows, run chcp 65001 before mysql. Then re-run SHOW VARIABLES LIKE 'character_set%'—if character_set_client isn't utf8mb4, reconnect with --default-character-set=utf8mb4.
  • "Incorrect string value" error on insert: This means the target column or table isn't utf8mb4. Verify with SHOW 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 (not utf8) and the column type is utf8mb4.
  • Connection resets after setting character sets: Some MySQL versions reject mismatched client/server collations. Use utf8mb4_unicode_ci (not _bin or 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.log or MySQL data directory) for character-set-related warnings.

Frequently Asked Questions

Does MySQL 8.0 support full Unicode including emojis?

Yes—using the utf8mb4 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 with ALTER 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 run chcp 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. Run ALTER 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 configure default-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 on utf8mb4 for all tables to avoid encoding conflicts in joins or unions.