Death Programmer
Death Programmer

Reputation: 896

Is there a difference between utf-8 and normal text length storage in mysql

If save two utf-8 and normal text(only English character) in text field
is there a difference between storage length in database(maybe convert not English character to English character)?

Example: if i save ali word in database, save as : ali
but if i save علی word in database, save as : some code more than 3 char

Database: MySQL Engine : InnoDB

Upvotes: 1

Views: 169

Answers (1)

Nadeem_MK
Nadeem_MK

Reputation: 7689

The idea of UTF-8 is that various Unicode characters are encoded using byte sequences of different lengths:

  • Basic Latin letters, digits, and punctuation signs use one byte.
  • Most European and Middle East script letters fit into a 2-byte sequence: extended Latin letters (with tilde, macron, acute, grave and other accents), Cyrillic, Greek, Armenian, Hebrew, Arabic, Syriac, and others.
  • Korean, Chinese, and Japanese ideographs use 3-bytes sequences.

Tip: To save space with UTF-8, use VARCHAR instead of CHAR. Otherwise, MySQL must reserve three bytes for each character in a CHAR CHARACTER SET utf8 column because that is the maximum possible length. For example, MySQL must reserve 30 bytes for a CHAR(10) CHARACTER SET utf8 column.

Upvotes: 2

Related Questions