Character sets and collations in MySQL

Click for: original source

Understanding the differences between character sets and collations in MySQL. Character sets and collations are fundamentally important concepts to understand when dealing with string columns in MySQL. A slight misunderstanding of either can lead to poor performance or unexpected errors when inserting data. By planetscale.com.

The article then goes over (with examples):

  • Character sets in MySQL
  • How do you define a character set?
  • Collations in MySQL#
  • How do you define a collation?#

MySQL supports a wide range of character sets, which you can view by selecting from the information_schema database. There are a few ways to define the character set of a column. If you don’t specify a character set at the table or column level, the server default of utf8mb4 will be applied (unless you’ve explicitly declared a different server or database default).

While character sets define the legal characters that can be stored in a column, collations are rules that determine how string comparisons are made. If you are sorting or comparing strings, MySQL uses the collation to decide the order and whether the strings are the same. Understanding character sets and collations is fundamental when dealing with string data in MySQL. A character set defines the legal characters that can be stored in a column, while a collation determines how string comparisons are made. Good read!

[Read More]

Tags web-development app-development mysql database how-to