{
  "id": "database/mysql-unknown-collation",
  "signature": "ERROR 1273 (HY000): Unknown collation: 'utf8mb4_0900_ai_ci'",
  "signature_zh": "错误 1273 (HY000): 未知的排序规则：'utf8mb4_0900_ai_ci'",
  "regex": "ERROR 1273 \\(HY000\\): Unknown collation: 'utf8mb4_0900_ai_ci'",
  "domain": "database",
  "category": "encoding_error",
  "subcategory": null,
  "root_cause": "A MySQL database or table uses a collation (utf8mb4_0900_ai_ci) that is not supported by the current server version, typically because the collation was introduced in MySQL 8.0 but the server is on an older version (e.g., 5.7 or 5.6).",
  "root_cause_type": "generic",
  "root_cause_zh": "MySQL 数据库或表使用了当前服务器版本不支持的排序规则（utf8mb4_0900_ai_ci），通常是因为该排序规则是在 MySQL 8.0 中引入的，但服务器运行在较旧版本（例如 5.7 或 5.6）上。",
  "versions": [
    {
      "version": "MySQL 5.7.44",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "MySQL 5.6.51",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "MariaDB 10.11.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Changing the collation to a random one like 'utf8mb4_general_ci' without checking table definitions",
      "why_fails": "This may work for some tables but can cause data inconsistency if the original collation had specific requirements (e.g., case sensitivity); also, it requires altering each table individually.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Upgrading MySQL to 8.0 without testing compatibility",
      "why_fails": "While upgrading fixes the collation issue, it may introduce other incompatibilities (e.g., SQL syntax changes, deprecated features) that break the application.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    },
    {
      "action": "Ignoring the error and continuing with the import",
      "why_fails": "The error stops the import process; ignoring it will result in an incomplete or failed database restore.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Replace the collation in the SQL dump file using sed: sed -i 's/utf8mb4_0900_ai_ci/utf8mb4_general_ci/g' dump.sql, then import the modified dump: mysql -u root -p mydb < dump.sql.",
      "success_rate": 0.85,
      "how": "Replace the collation in the SQL dump file using sed: sed -i 's/utf8mb4_0900_ai_ci/utf8mb4_general_ci/g' dump.sql, then import the modified dump: mysql -u root -p mydb < dump.sql.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If the dump is from a MySQL 8.0 database, use mysqldump with the --compatible=mysql56 flag to generate a dump compatible with older versions: mysqldump --compatible=mysql56 -u root -p mydb > dump.sql.",
      "success_rate": 0.8,
      "how": "If the dump is from a MySQL 8.0 database, use mysqldump with the --compatible=mysql56 flag to generate a dump compatible with older versions: mysqldump --compatible=mysql56 -u root -p mydb > dump.sql.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Manually alter the collation of the affected tables after import (if the import partially succeeds): ALTER TABLE my_table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;",
      "success_rate": 0.78,
      "how": "Manually alter the collation of the affected tables after import (if the import partially succeeds): ALTER TABLE my_table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Replace the collation in the SQL dump file using sed: sed -i 's/utf8mb4_0900_ai_ci/utf8mb4_general_ci/g' dump.sql, then import the modified dump: mysql -u root -p mydb < dump.sql.",
    "If the dump is from a MySQL 8.0 database, use mysqldump with the --compatible=mysql56 flag to generate a dump compatible with older versions: mysqldump --compatible=mysql56 -u root -p mydb > dump.sql.",
    "Manually alter the collation of the affected tables after import (if the import partially succeeds): ALTER TABLE my_table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-utf8mb4.html",
  "official_doc_section": null,
  "error_code": "1273",
  "verification_tier": "ai_generated",
  "confidence": 0.86,
  "fix_success_rate": 0.83,
  "resolvable": "true",
  "first_seen": "2024-03-18",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}