• <tfoot id='l080o'></tfoot>
  • <i id='l080o'><tr id='l080o'><dt id='l080o'><q id='l080o'><span id='l080o'><b id='l080o'><form id='l080o'><ins id='l080o'></ins><ul id='l080o'></ul><sub id='l080o'></sub></form><legend id='l080o'></legend><bdo id='l080o'><pre id='l080o'><center id='l080o'></center></pre></bdo></b><th id='l080o'></th></span></q></dt></tr></i><div id='l080o'><tfoot id='l080o'></tfoot><dl id='l080o'><fieldset id='l080o'></fieldset></dl></div>
      <bdo id='l080o'></bdo><ul id='l080o'></ul>
    <legend id='l080o'><style id='l080o'><dir id='l080o'><q id='l080o'></q></dir></style></legend>

    1. <small id='l080o'></small><noframes id='l080o'>

        操作 '=' 的排序规则 (utf8_unicode_ci,IMPLICIT) 和 (utf8_gene

        时间:2023-06-02

        <small id='RwDfJ'></small><noframes id='RwDfJ'>

        <legend id='RwDfJ'><style id='RwDfJ'><dir id='RwDfJ'><q id='RwDfJ'></q></dir></style></legend>

          <tfoot id='RwDfJ'></tfoot>
              • <bdo id='RwDfJ'></bdo><ul id='RwDfJ'></ul>

                  <tbody id='RwDfJ'></tbody>
              • <i id='RwDfJ'><tr id='RwDfJ'><dt id='RwDfJ'><q id='RwDfJ'><span id='RwDfJ'><b id='RwDfJ'><form id='RwDfJ'><ins id='RwDfJ'></ins><ul id='RwDfJ'></ul><sub id='RwDfJ'></sub></form><legend id='RwDfJ'></legend><bdo id='RwDfJ'><pre id='RwDfJ'><center id='RwDfJ'></center></pre></bdo></b><th id='RwDfJ'></th></span></q></dt></tr></i><div id='RwDfJ'><tfoot id='RwDfJ'></tfoot><dl id='RwDfJ'><fieldset id='RwDfJ'></fieldset></dl></div>
                • 本文介绍了操作 '=' 的排序规则 (utf8_unicode_ci,IMPLICIT) 和 (utf8_general_ci,IMPLICIT) 的非法混合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  MySql 上的错误信息:

                  Error message on MySql:

                  Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '='
                  

                  我已经浏览了其他几篇文章,但未能解决此问题.受影响的部分与此类似:

                  I have gone through several other posts and was not able to solve this problem. The part affected is something similar to this:

                  CREATE TABLE users (
                      userID INT UNSIGNED NOT NULL AUTO_INCREMENT,
                      firstName VARCHAR(24) NOT NULL,
                      lastName VARCHAR(24) NOT NULL,
                      username VARCHAR(24) NOT NULL,
                      password VARCHAR(40) NOT NULL,
                      PRIMARY KEY (userid)
                  ) ENGINE = INNODB CHARACTER SET utf8 COLLATE utf8_unicode_ci;
                  
                  CREATE TABLE products (
                      productID INT UNSIGNED NOT NULL AUTO_INCREMENT,
                      title VARCHAR(104) NOT NULL,
                      picturePath VARCHAR(104) NULL,
                      pictureThumb VARCHAR(104) NULL,
                      creationDate DATE NOT NULL,
                      closeDate DATE NULL,
                      deleteDate DATE NULL,
                      varPath VARCHAR(104) NULL,
                      isPublic TINYINT(1) UNSIGNED NOT NULL DEFAULT '1',
                      PRIMARY KEY (productID)
                  ) ENGINE = INNODB CHARACTER SET utf8 COLLATE utf8_unicode_ci;
                  
                  CREATE TABLE productUsers (
                      productID INT UNSIGNED NOT NULL,
                      userID INT UNSIGNED NOT NULL,
                      permission VARCHAR(16) NOT NULL,
                      PRIMARY KEY (productID,userID),
                      FOREIGN KEY (productID) REFERENCES products (productID) ON DELETE RESTRICT ON UPDATE NO ACTION,
                      FOREIGN KEY (userID) REFERENCES users (userID) ON DELETE RESTRICT ON UPDATE NO ACTION
                  ) ENGINE = INNODB CHARACTER SET utf8 COLLATE utf8_unicode_ci;
                  

                  我使用的存储过程是这样的:

                  The stored procedure I'm using is this:

                  CREATE PROCEDURE updateProductUsers (IN rUsername VARCHAR(24),IN rProductID INT UNSIGNED,IN rPerm VARCHAR(16))
                  BEGIN
                      UPDATE productUsers
                          INNER JOIN users
                          ON productUsers.userID = users.userID
                          SET productUsers.permission = rPerm
                          WHERE users.username = rUsername
                          AND productUsers.productID = rProductID;
                  END
                  

                  我正在用 php 进行测试,但 SQLyog 出现了同样的错误.我还测试了重新创建整个数据库,但效果不佳.

                  I was testing with php, but the same error is given with SQLyog. I have also tested recreating the entire DB but to no good.

                  任何帮助将不胜感激.

                  推荐答案

                  存储过程参数的默认排序规则是 utf8_general_ci 并且您不能混合排序规则,因此您有四个选项:

                  The default collation for stored procedure parameters is utf8_general_ci and you can't mix collations, so you have four options:

                  选项 1:将 COLLATE 添加到您的输入变量:

                  Option 1: add COLLATE to your input variable:

                  SET @rUsername = ‘aname’ COLLATE utf8_unicode_ci; -- COLLATE added
                  CALL updateProductUsers(@rUsername, @rProductID, @rPerm);
                  

                  选项 2:将 COLLATE 添加到 WHERE 子句:

                  Option 2: add COLLATE to the WHERE clause:

                  CREATE PROCEDURE updateProductUsers(
                      IN rUsername VARCHAR(24),
                      IN rProductID INT UNSIGNED,
                      IN rPerm VARCHAR(16))
                  BEGIN
                      UPDATE productUsers
                          INNER JOIN users
                          ON productUsers.userID = users.userID
                          SET productUsers.permission = rPerm
                          WHERE users.username = rUsername COLLATE utf8_unicode_ci -- COLLATE added
                          AND productUsers.productID = rProductID;
                  END
                  

                  选项 3:将其添加到 IN 参数定义(MySQL 5.7 之前):

                  Option 3: add it to the IN parameter definition (pre-MySQL 5.7):

                  CREATE PROCEDURE updateProductUsers(
                      IN rUsername VARCHAR(24) COLLATE utf8_unicode_ci, -- COLLATE added
                      IN rProductID INT UNSIGNED,
                      IN rPerm VARCHAR(16))
                  BEGIN
                      UPDATE productUsers
                          INNER JOIN users
                          ON productUsers.userID = users.userID
                          SET productUsers.permission = rPerm
                          WHERE users.username = rUsername
                          AND productUsers.productID = rProductID;
                  END
                  

                  选项 4:更改字段本身:

                  ALTER TABLE users CHARACTER SET utf8 COLLATE utf8_general_ci;
                  

                  除非您需要按 Unicode 顺序对数据进行排序,否则我建议您更改所有表以使用 utf8_general_ci 排序规则,因为它不需要更改代码,并且会稍微加快排序速度.

                  Unless you need to sort data in Unicode order, I would suggest altering all your tables to use utf8_general_ci collation, as it requires no code changes, and will speed sorts up slightly.

                  更新:utf8mb4/utf8mb4_unicode_ci 现在是首选的字符集/整理方法.不建议使用 utf8_general_ci,因为性能改进可以忽略不计.请参阅https://stackoverflow.com/a/766996/1432614

                  UPDATE: utf8mb4/utf8mb4_unicode_ci is now the preferred character set/collation method. utf8_general_ci is advised against, as the performance improvement is negligible. See https://stackoverflow.com/a/766996/1432614

                  这篇关于操作 '=' 的排序规则 (utf8_unicode_ci,IMPLICIT) 和 (utf8_general_ci,IMPLICIT) 的非法混合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  • <bdo id='0CKS0'></bdo><ul id='0CKS0'></ul>
                      <tfoot id='0CKS0'></tfoot>

                          <tbody id='0CKS0'></tbody>

                        <i id='0CKS0'><tr id='0CKS0'><dt id='0CKS0'><q id='0CKS0'><span id='0CKS0'><b id='0CKS0'><form id='0CKS0'><ins id='0CKS0'></ins><ul id='0CKS0'></ul><sub id='0CKS0'></sub></form><legend id='0CKS0'></legend><bdo id='0CKS0'><pre id='0CKS0'><center id='0CKS0'></center></pre></bdo></b><th id='0CKS0'></th></span></q></dt></tr></i><div id='0CKS0'><tfoot id='0CKS0'></tfoot><dl id='0CKS0'><fieldset id='0CKS0'></fieldset></dl></div>
                        <legend id='0CKS0'><style id='0CKS0'><dir id='0CKS0'><q id='0CKS0'></q></dir></style></legend>
                      1. <small id='0CKS0'></small><noframes id='0CKS0'>