如何查看MySQL数据库/表/列的字符集?
为了检查MySQL数据库/表/列的字符集,让我们看一个例子:使用数据库中已经存在的名称为“ business”且表名为“ student”的数据库。
语法以检查表字符集。
SELECT CCSA.character_set_nameFROM information_schema.`TABLES` T,information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA
WHERE CCSA.collation_name = T.table_collation
AND T.table_schema = "yourDatabaseName"
AND T.table_name = "yourTableName";
应用以上语法为学生表显示字符集。
mysql> SELECT CCSA.character_set_nameFROM information_schema.`TABLES` T,
-> information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA
-> WHERE CCSA.collation_name = T.table_collation
-> AND T.table_schema = "business"
-> AND T.table_name = "student";
以下是输出。
+--------------------+| CHARACTER_SET_NAME |
+--------------------+
| utf8mb4 |
+--------------------+
1 row in set (0.13 sec)
要查找数据库的字符集,请使用以下语法。
SELECT default_character_set_name FROM information_schema.SCHEMATAWHERE schema_name = "yourDatabaseName";
应用以上语法以查看数据库的字符集。
mysql> SELECT default_character_set_name FROM information_schema.SCHEMATA-> WHERE schema_name = "business";
以下是输出。
+----------------------------+| DEFAULT_CHARACTER_SET_NAME |
+----------------------------+
| utf8mb4 |
+----------------------------+
1 row in set (0.00 sec)
查找列的字符集。
SELECT character_set_name FROM information_schema.`COLUMNS`WHERE table_schema = "yourDatabaseName"
AND table_name = "yourTableName"
AND column_name = "yourColumnName";
应用以上语法,以查看“学生”表和“业务”数据库的列名“名称”是什么字符集。
mysql> SELECT character_set_name FROM information_schema.`COLUMNS`-> WHERE table_schema = "business"
-> AND table_name = "student"
-> AND column_name = "Name";
以下是输出。
+--------------------+| CHARACTER_SET_NAME |
+--------------------+
| utf8mb4 |
+--------------------+
1 row in set (0.00 sec)
以上是 如何查看MySQL数据库/表/列的字符集? 的全部内容, 来源链接: utcz.com/z/317009.html