我正在尝试解决字符编码问题-以前我们为此列utf8_general_ci设置了归类设置,这引起了问题,因为它对重音不敏感。

我正在尝试查找数据库中可能已经受到影响的所有条目。

set names utf8;
select * from table1 t1 join table2 t2 on (t1.pid=t2.pid and t1.id != t2.id) collate utf8_general_ci;

但是,这会产生错误:
ERROR 1253 (42000): COLLATION 'utf8_general_ci' is not valid for CHARACTER SET 'latin1'
  • 现在使用DEFAULT CHARACTER SET utf8定义了数据库
  • 该表使用CHARSET=utf8定义
  • “pid”列定义为:CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
  • 服务器版本为服务器版本:5.5.37-MariaDB-0ubuntu0.14.04.1(Ubuntu)

  • 问题:当在表/模式定义的任何地方似乎都不存在latin1时,为什么会出现关于latin1的错误?
    MariaDB [(none)]> SHOW VARIABLES LIKE '%char%';
    +--------------------------+----------------------------+
    | Variable_name            | Value                      |
    +--------------------------+----------------------------+
    | character_set_client     | utf8                       |
    | character_set_connection | utf8                       |
    | character_set_database   | latin1                     |
    | character_set_filesystem | binary                     |
    | character_set_results    | utf8                       |
    | character_set_server     | latin1                     |
    | character_set_system     | utf8                       |
    | character_sets_dir       | /usr/share/mysql/charsets/ |
    +--------------------------+----------------------------+
    8 rows in set (0.00 sec)
    
    MariaDB [(none)]> SHOW VARIABLES LIKE '%collation%';
    +----------------------+-------------------+
    | Variable_name        | Value             |
    +----------------------+-------------------+
    | collation_connection | utf8_general_ci   |
    | collation_database   | latin1_swedish_ci |
    | collation_server     | latin1_swedish_ci |
    +----------------------+-------------------+
    

    最佳答案

    首先运行此查询

    SHOW VARIABLES LIKE '%char%';
    

    您有character_set_server='latin1'
    如果是这样,进入您的配置文件my.cnf并添加或取消注释以下行:
    character-set-server = utf8
    collation-server = utf8_unicode_ci
    

    重新启动服务器。
    是的,聚会晚了,只是遇到了同样的问题。

    关于mysql - COLLATION 'utf8_general_ci'不适用于CHARACTER SET 'latin1',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25852239/

    10-10 23:20