How to change Column Collation without losing or changing data?

前端 未结 2 478
隐瞒了意图╮
隐瞒了意图╮ 2020-12-21 05:58

I have been using mysql version 5.5.41 and have run into an issue. I change the collation of a specific column in my table from latin1_swedish_ci to hebrew_bin, and this ch

相关标签:
2条回答
  • 2020-12-21 06:24

    You must change CHANGE by MODIFY

    The first step is to convert the column to a binary data type, which removes the existing character set information without performing any character conversion:

    ALTER TABLE something MODIFY name BLOB;
    

    The next step is to convert the column to a nonbinary data type with the proper character set:

    ALTER TABLE something MODIFY name VARCHAR(12) CHARACTER SET hebrew COLLATE hebrew_bin;
    

    Or Try with this:

    ALTER TABLE something MODIFY name VARCHAR(12) CHARACTER SET utf8 COLLATE utf8_unicode_ci
    

    Read more at:

    http://dev.mysql.com/doc/refman/5.5/en/charset-conversion.html

    http://dev.mysql.com/doc/refman/5.5/en/charset-column.html

    Please note that running any MODIFY or CHANGE operation on a column will (in a practical sense) remove any default value or comment on the column, as per the documentation.

    When you use CHANGE or MODIFY, column_definition must include the data type and all attributes that should apply to the new column, other than index attributes such as PRIMARY KEY or UNIQUE. Attributes present in the original definition but not specified for the new definition are not carried forward.

    0 讨论(0)
  • 2020-12-21 06:45

    Please do SELECT HEX(col), col FROM ... to see what is stored for "école". Latin1 would look like E9636F6C65. Hebrew, if I am not mistaken, has not include 'é'. See http://collation-charts.org/mysql60/mysql604.hebrew_general_ci.html for what is probably the complete set of characters supported.

    Assuming that is correct, do no try to convert to CHARACTER SET hebrew; you will lose information, such as 'é' being turned into '?'.

    If you need to store both Hebrew characters and French accented characters (etc), use utf8.

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