mysql check collation of a table

 ̄綄美尐妖づ 提交于 2019-12-17 18:34:11

问题


How can I see what collation a table has? I.E. I want to see:

+-----------------------------+
|  table  |     collation     |
|-----------------------------|
| t_name  |  latin_general_ci |
+-----------------------------+

回答1:


SHOW TABLE STATUS shows information about a table, including the collation.

For example SHOW TABLE STATUS where name like 'TABLE_NAME'




回答2:


The above answer is great, but it doesn't actually provide an example that saves the user from having to look up the syntax:

show table status like 'test';

Where test is the table name.

(Corrected as per comments below.)




回答3:


You can also query INFORMATION_SCHEMA.TABLES and get the collation for a specific table:

SELECT TABLE_SCHEMA
    , TABLE_NAME
    , TABLE_COLLATION 
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME ='t_name';

that gives a much more readable output in contrast to SHOW TABLE STATUS that contains a lot of irrelevant information.

Note that collation can also be applied to columns (which might have a different collation than the table itself). To fetch the columns' collation for a particular table, you can query INFORMATION_SCHEMA.COLUMNS:

SELECT TABLE_SCHEMA 
    , TABLE_NAME 
    , COLUMN_NAME 
    , COLLATION_NAME 
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME ='t_name';



回答4:


Use this query:

SHOW CREATE TABLE tablename

You will get all information related to table.



来源:https://stackoverflow.com/questions/3832056/mysql-check-collation-of-a-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!