如何在一行中将归类更改为utf8_bin?

您需要使用ALTER命令将排序规则更改为utf8_bin。语法如下:

ALTER TABLE yourTableName COLLATE utf8_general_ci;

为了理解上述语法,让我们创建一个表。创建表的查询如下:

mysql> create table CollateDemo
   -> (
   -> Id int NOT NULL AUTO_INCREMENT,
   -> Name varchar(20),
   -> Age int,
   -> PRIMARY KEY(Id)
   -> );

检查表的DDL。语法如下:

SHOW CREATE TABLE yourTableName;

现在让我们检查表的DDL:

mysql> show create table CollateDemo;

以下是输出:

+-------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table       | Create Table                                                                                                                                                                                                               |
+-------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| CollateDemo | CREATE TABLE `collatedemo` (`Id` int(11) NOT NULL AUTO_INCREMENT, `Name` varchar(20) DEFAULT NULL, `Age` int(11) DEFAULT NULL, PRIMARY KEY (`Id`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci   |
+-------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

现在,您可以使用ALTER命令更改排序规则。查询如下:

mysql> alter table CollateDemo collate utf8_general_ci;
Records: 0 Duplicates: 0 Warnings: 0

现在让我们检查表的DDL:

mysql> show create table CollateDemo;

以下是输出:

+--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table       | Create Table                                                                                                                                                                                                  |
+-------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| CollateDemo | CREATE TABLE `collatedemo` (`Id` int(11) NOT NULL AUTO_INCREMENT, `Name` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL, `Age` int(11) DEFAULT NULL, PRIMARY KEY (`Id`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8       |
+-------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)