When to use utf-8 and when to use latin1 in MySQL?

后端 未结 8 1683
暖寄归人
暖寄归人 2021-02-13 21:56

I know that MySQL has default of latin1 encoding and apparently it takes 1 byte to store a character in latin1 and 3 bytes to store a character in

相关标签:
8条回答
  • 2021-02-13 22:25

    At a bare minimum I would suggest using UTF-8. Your data will be compatible with every other database out there nowadays since 90%+ of them are UTF-8.

    If you go with LATIN1/ISO-8859-1 you risk the data being not properly stored because it doesn't support international characters... so you might run into something like the left side of this image:

    enter image description here

    If you go with UTF-8, you don't need to deal with these headaches.

    Regarding your error, it sounds like you need to optimize your database. Consider this: http://bugs.mysql.com/bug.php?id=4541#c284415

    It would help if you gave specifics on your table schema and column for that issue.

    0 讨论(0)
  • 2021-02-13 22:31

    In my experience, if you plan to support Arabic, Russian, Asian languages or others, the investment in UTF-8 support upfront will pay off down the line. However, depending on your circumstances you may be able to get away with English for a while.

    As for the error, you probably have a key or index field with more than 333 characters, the maximum allowed in MySQL with UTF-8 encoding. See this bug report.

    0 讨论(0)
提交回复
热议问题