MySQL 如何查看MySQL数据库/表/列的字符集
为了检查MySQL数据库/表/列的字符集,让我们看一个例子:使用已经存在于数据库中的名称为“business”的数据库和名称为“student”的表。
检查表字符集的语法。
SELECT CCSA.character_set_name
FROM 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";
应用上述语法以显示表“student”的字符集。
mysql> SELECT CCSA.character_set_name
FROM 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.SCHEMATA
WHERE 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";
应用上述语法以查看名称为“Name”的列的字符集,适用于“student”表和“business”数据库。
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 教程