Why my MySQL DB can store Arabic characters correctly with latin1 encoding? -
test select:
mysql [chuangwai]> select ar_detail items limit 1\g; *************************** 1. row *************************** ar_detail: {"طراز": "فساتين قفطان", "المواد": "الشيفون"}
and can see arabic characters displayed correctly.
then check encoding:
mysql [chuangwai]> select * information_schema.schemata\g; *************************** 2. row *************************** catalog_name: def schema_name: chuangwai default_character_set_name: latin1 default_collation_name: latin1_swedish_ci sql_path: null
if you're trying store non-latin characters chinese, japanese, hebrew, cyrillic, etc using latin1 encoding, end mojibake.
as see, not case. please give me explanation why can store arabic characters latin1
encoding? necessary switch encoding of our db latin1
uft8
?
edit: okay, found encoding of items
uft8
...
mysql [chuangwai]> select table_collation -> information_schema.tables -> table_name = 'items'; +-----------------+ | table_collation | +-----------------+ | utf8_unicode_ci | +-----------------+
most explanation table utf8, if schema ascii. try
select table_collation information_schema.tables table_name = 'items';
in case, utf8
table gives me: utf8_general_ci
. might see utf8mb4_general_ci
instead (that's better utf8_general_ci
variety of reasons)
now, question "is necessary switch encodings?" answer "technically, no, idea." long include encoding in table definitions, won't need worry schema encoding. still, better switch encoding don't need worry accidentally munging data later.
Comments
Post a Comment