如何在单行文本中将对照转换为 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) -> ); Query OK, 0 rows affected (0.98 sec)
检查表的 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; Query OK, 0 rows affected (0.39 sec) 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)
广告