Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I know this is a silly question, but I understand from that link

MySQL :: MySQL 8.0 Reference Manual :: 10.10.1 Unicode Character Sets[^]

MySQL :: MySQL 8.0 Reference Manual :: 11.7 Data Type Storage Requirements[^]

that CHAR support wide character EG: Unicode, Utf8, etc.
But TEXT is only string support only AnsiC.

If so...

Its inconsistency with C language Data Type concept which indicate CHAR as AnsiC string.

how to understand Mysql theorizm ?

What I have tried:

I have tried Input text as utf8 and also it returned utf8.
Posted
Updated 31-Mar-20 20:26pm
v3
Comments
KarstenK 30-Mar-20 8:07am    
Be very careful, best is NOT to use TEXT. This avoids bugs when some text operations are using the database.

OriginalGriff is absolut correct.

1 solution

ANSI C uses the ASCII charact6ers set - which is a 7 bit code set, with a limited range of characters available. These map exactly into the "bottom 128" of the Unicode characters set, so storing ASCII in Unicode is trivial. But going the other way ...

Unicode has more characters available - it's effectively a 16 bit codeset - and UTF8 stores most characters in a single 8 bit byte, which does fit into a CHAR as its' actually stored as an 8 bit value, not 7 bits. But ... once you move outside the "basic" character sets, it becomes a problem, and the number of bytes needed to store a UTF character is not fixed at one (as ASCII is) - it's flexible, so it can store wider Unicode values in a series of 8 bit characters.

So while you can specify "ten characters" in TEXT fields, and get 10 ASCII characters in there every time, you can't necessarily store 10 Unicode characters in there, even if they are UTF8 as the number of bytes needed to store the ten characters can be between ten and twenty depending on the actual data you store.

CHAR fields allocate 16 bits per character, so the whole Unicode character set can always be stored.

If in doubt, always use CHAR rather than TEXT.
 
Share this answer
 
Comments
Member 11010948 30-Mar-20 8:34am    
Vice-versa. ASCII uses POSIX ANSI-C-7bit characterset! ASCII size is 1byte, UNICODE size is 2bytes. and you didnot answer the question. can TEXT also get 16bit character size ?
Maciej Los 30-Mar-20 9:09am    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900