What will happen to existing data if I change the collation of a column in MySQL?

前端 未结 5 490
无人及你
无人及你 2021-01-12 02:37

I am running a production application with MySQL database server. I forget to set column\'s collation from latin to utf8_unicode, which results in

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-12 03:09

    CAUTION! Some problems are solved via

    ALTER TABLE ... CONVERT TO ...
    

    Some are solved via a 2-step process

    ALTER TABLE ... MODIFY ... VARBINARY...
    ALTER TABLE ... MODIFY ... VARCHAR...
    

    If you do the wrong one, you will have a worse mess!

    1. Do SELECT HEX(col), col ... to see what you really have.
    2. Study this to see what case you have: Trouble with utf8 characters; what I see is not what I stored
    3. Perform the correct fix, based on these cases: http://mysql.rjweb.org/doc.php/charcoll#fixes_for_various_cases

提交回复
热议问题