{"id":11369,"date":"2023-12-08T13:48:54","date_gmt":"2023-12-08T05:48:54","guid":{"rendered":"https:\/\/nj.transwarp.cn:8180\/?p=11369"},"modified":"2023-12-08T17:47:44","modified_gmt":"2023-12-08T09:47:44","slug":"kundb-join%e6%8a%a5%e9%94%99illegal-mix-of-collations-utf8mb4_cs_0900_ai_ciimplicit-and-utf8mb4_0900_ai_ciimplicit-for-operation","status":"publish","type":"post","link":"https:\/\/kbwp.transwarp.cn\/?p=11369","title":{"rendered":"kundb join\u62a5\u9519Illegal mix of collations"},"content":{"rendered":"<h3>\u6982\u8981\u63cf\u8ff0<\/h3>\n<hr \/>\n<p>\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u6267\u884c kundb sql \u62a5\u9519<code>Illegal mix of collations (utf8mb4_cs_0900_ai_ci,IMPLICIT) and (utf8mb4_0900_ai_ci,IMPLICIT) for operation &#039;=&#039;<\/code>\u7684\u6392\u67e5\u601d\u8def\u548c\u89e3\u51b3\u529e\u6cd5\u3002<\/p>\n<h3>\u8be6\u7ec6\u8bf4\u660e<\/h3>\n<hr \/>\n<h4>\u521b\u5efa\u6837\u4f8b\u8868<\/h4>\n<pre><code class=\"language-sql\">drop table if exists table1;\nCREATE TABLE table1 (  \n    id INT PRIMARY KEY AUTO_INCREMENT,  \n    name VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_cs_0900_ai_ci NOT NULL,  \n    age INT  \n);\n\ndrop table if exists table2;\nCREATE TABLE table2 (  \n    id INT PRIMARY KEY AUTO_INCREMENT,  \n    name VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,  \n    age INT  \n);<\/code><\/pre>\n<h4>\u6267\u884cjoin\u64cd\u4f5c<\/h4>\n<pre><code class=\"language-sql\">SELECT table1.name, table2.name   \nFROM table1   \nJOIN table2 ON table1.name = table2.name;<\/code><\/pre>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2023\/12\/image-1702014294828.png\" alt=\"file\" \/><\/p>\n<p>\u8fd9\u4e2a\u9519\u8bef\u662f\u56e0\u4e3a\u4f60\u8bd5\u56fe\u8fde\u63a5\u7684\u4e24\u5f20\u8868\u6216\u8005\u5176\u4e2d\u7684\u5217\u4f7f\u7528\u7684\u5b57\u7b26\u96c6\uff08collation\uff09\u4e0d\u5339\u914d\u3002\u5728MySQL\u4e2d\uff0c\u5b57\u7b26\u96c6\u548c\u6392\u5e8f\u89c4\u5219\u662f\u76f8\u5173\u7684\u3002\u6bd4\u5982\uff0cutf8mb4\u662f\u5b57\u7b26\u96c6\uff0c\u800cutf8mb4_general_ci\u548cutf8mb4_cs_0900_ai_ci\u662futf8mb4\u7684\u4e24\u79cd\u4e0d\u540c\u7684\u6392\u5e8f\u89c4\u5219\u3002<\/p>\n<h3>\u89e3\u51b3\u65b9\u6848<\/h3>\n<hr \/>\n<h4>\u65b9\u6848\u4e00\uff1a\u5728JOIN\u64cd\u4f5c\u4e2d\u4f7f\u7528COLLATE\u6765\u660e\u786e\u6307\u5b9a\u76f8\u540c\u7684\u6392\u5e8f\u89c4\u5219\uff1a<\/h4>\n<pre><code class=\"language-sql\">SELECT table1.name, table2.name   \nFROM table1   \nJOIN table2 ON table1.name COLLATE utf8mb4_general_ci = table2.name COLLATE utf8mb4_general_ci;<\/code><\/pre>\n<h4>\u65b9\u6848\u4e8c\uff1a\u66f4\u6539\u5176\u4e2d\u4e00\u4e2a\u8868\u7684\u5b57\u7b26\u96c6\u6216\u6392\u5e8f\u89c4\u5219\uff0c\u4f7f\u5176\u4e0e\u53e6\u4e00\u4e2a\u8868\u5339\u914d\u3002<\/h4>\n<p>\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u5c06 table2 \u7684 name \u5217\u7684\u6392\u5e8f\u89c4\u5219\u66f4\u6539\u4e3a utf8mb4_cs_0900_ai_ci\uff1a<\/p>\n<pre><code class=\"language-sql\">ALTER TABLE table1 MODIFY name VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;<\/code><\/pre>\n<p><strong>FAQ:<\/strong><\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7 <code>show full columns from table1<\/code> \u7684\u65b9\u5f0f\u786e\u8ba4\u5217\u7684\u5b57\u7b26\u96c6\u548c\u6392\u5e8f\u89c4\u5219\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8981\u63cf\u8ff0 \u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u6267\u884c kundb sql \u62a5\u9519Illegal mix of collations (ut ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/kbwp.transwarp.cn\/?p=11369\" title=\"read more...\">Read more<\/a><\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-11369","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"acf":[],"_links":{"self":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/11369","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11369"}],"version-history":[{"count":2,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/11369\/revisions"}],"predecessor-version":[{"id":11372,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/11369\/revisions\/11372"}],"wp:attachment":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}