发现 MySQL 列的整理

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7617412/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:13:17  来源:igfitidea点击:

Discover collation of a MySQL column

mysqlcollation

提问by Trindaz

I previously created a MySQL table and now I want to find out what collation some of the fields are using. What SQL or MySQL commands can I use to discover this?

我之前创建了一个 MySQL 表,现在我想找出某些字段正在使用的排序规则。我可以使用哪些 SQL 或 MySQL 命令来发现这一点?

回答by 0x4a6f4672

You could use SHOW FULL COLUMNS FROM tablenamewhich returns a column Collation, for example for a table 'accounts' with a special collation on the column 'name'

您可以使用SHOW FULL COLUMNS FROM tablenamewhich 返回一列Collat​​ion,例如对于在列 'name' 上具有特殊排序规则的表 'accounts'

mysql> SHOW FULL COLUMNS FROM accounts;
+----------+--------------+-------------------+------+-----+---------+----------+
| Field    | Type         | Collation         | Null | Key | Default | Extra    |
+----------+--------------+-------------------+------+-----+---------+----------|
| id       | int(11)      | NULL              | NO   | PRI | NULL    | auto_inc |
| name     | varchar(255) | utf8_bin          | YES  |     | NULL    |          |
| email    | varchar(255) | latin1_swedish_ci | YES  |     | NULL    |          |
...

Or you could use SHOW CREATE TABLE tablenamewhich will result in a statement like

或者您可以使用SHOW CREATE TABLE tablenamewhich 将导致类似的语句

mysql> SHOW CREATE TABLE accounts;
CREATE TABLE `accounts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
...

回答by HoldOffHunger

If you want the collation for just that specific column (for possible use with a subquery)...

如果您只想要该特定列的排序规则(可能与子查询一起使用)...

SELECT COLLATION_NAME
FROM information_schema.columns
WHERE TABLE_SCHEMA = 'tableschemaname'
AND TABLE_NAME = 'tablename'
AND COLUMN_NAME = 'fieldname';

回答by Explosion Pills

SHOW CREATE TABLE tablename will show you the collation of each column as well as the default collation

SHOW CREATE TABLE tablename 将显示每列的排序规则以及默认排序规则