Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Have you ever saved a customer's Hindi name (राजेश शर्मा), a Spanish name (Señor Müller), or a smartphone emoji (🚀, 😊) into a database, only to see it stored as garbled question marks (????) or crashing your application with Incorrect string value?
This error happens when you misunderstand Character Sets and Collations. In this tutorial, you will master international character encoding in MySQL.
A Character Set is a defined mapping between a collection of human-readable symbols and their underlying binary byte representations.
utf8 Trap in Older MySQL Versionsutf8 (now renamed utf8mb3), which only allocated 3 bytes per character!utf8mb4, which allocates the full 4 bytes per character.While a character set determines how characters are encoded, a Collation determines how characters are compared and sorted.
For example, should the letter 'a' be treated as equal to 'A'? Should 'e' be equal to 'é'? A collation answers these questions!
Consider the collation name: utf8mb4_0900_ai_ci
utf8mb4: Associated character set.0900: Unicode Collation Algorithm (UCA) version 9.0.0._ai: Accent Insensitive (e = é)._ci: Case Insensitive (a = A)._bin: Binary comparison (compares raw byte values directly; case-sensitive and accent-sensitive).MySQL allows specifying character sets and collations hierarchically across four distinct levels:
+-------------------------------------------------------------+
| 1. Server Default | Configured in my.cnf / my.ini |
+-------------------------------------------------------------+
| Inherited if unspecified
v
+-------------------------------------------------------------+
| 2. Database Default | CREATE DATABASE ... CHARACTER SET |
+-------------------------------------------------------------+
| Inherited if unspecified
v
+-------------------------------------------------------------+
| 3. Table Default | CREATE TABLE ... DEFAULT CHARSET |
+-------------------------------------------------------------+
| Inherited if unspecified
v
+-------------------------------------------------------------+
| 4. Column Level | col_name VARCHAR(100) CHARACTER SET |
+-------------------------------------------------------------+utf8mb4_0900_ai_ci is the default collation and the recommended standard for almost all international web applications._bin) so that 'Token123' does not match 'token123'.charset=utf8mb4 to avoid client-side transcoding bugs.utf8mb4 character set allocate in MySQL?_ci suffix represent in a MySQL collation name like utf8mb4_unicode_ci?DEFAULT CHARSET clause, where does it inherit its character set from?utf8mb4?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Selecting & Dropping Databases | Database Metadata & Server Status |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.