Home > OS >  How can I get all attributes of a column in mysql?
How can I get all attributes of a column in mysql?

Time:06-04

enter image description here As you can see above, columns have 13 attributes, they respectively are

  • Field
  • Type
  • Length
  • Unsigned
  • Zerofill
  • Binary
  • Allow Null
  • Key
  • Default
  • Extra
  • Encoding
  • Collation
  • Comment

I can see them because I'm using a visual mysql client software, but if I'm using a Terminal, a commandline client, I can only see the following attributes

mysql> desc user;
 ---------- -------------- ------ ----- --------- ---------------- 
| Field    | Type         | Null | Key | Default | Extra          |
 ---------- -------------- ------ ----- --------- ---------------- 
| id       | int unsigned | NO   | PRI | NULL    | auto_increment |
| name     | varchar(20)  | NO   | MUL |         |                |
| nickname | varchar(50)  | YES  | UNI | NULL    |                |
| age      | tinyint      | YES  |     | NULL    |                |
 ---------- -------------- ------ ----- --------- ---------------- 
4 rows in set (0.00 sec)

There are no zerofill, binary, encoding, collation and comment in the result of desc <tbl_name>, any other commands can see these attributes? especially comment.

CodePudding user response:

You can use the columns metadata table to get this:

SELECT  *
FROM information_schema.columns 
WHERE (table_schema='schema_name' and table_name = 'table_name')
order by ordinal_position;

CodePudding user response:

I found an answer from here, that is

show full columns from <tbl_name>;

Example

mysql> show full columns from user;
 ---------- -------------- -------------------- ------ ----- --------- ---------------- --------------------------------- ---------- 
| Field    | Type         | Collation          | Null | Key | Default | Extra          | Privileges                      | Comment  |
 ---------- -------------- -------------------- ------ ----- --------- ---------------- --------------------------------- ---------- 
| id       | int unsigned | NULL               | NO   | PRI | NULL    | auto_increment | select,insert,update,references | id       |
| name     | varchar(20)  | utf8mb4_general_ci | NO   | MUL |         |                | select,insert,update,references | name     |
| nickname | varchar(50)  | utf8mb4_general_ci | YES  | UNI | NULL    |                | select,insert,update,references | nickname |
| age      | tinyint      | NULL               | YES  |     | NULL    |                | select,insert,update,references | age      |
 ---------- -------------- -------------------- ------ ----- --------- ---------------- --------------------------------- ---------- 
4 rows in set (0.00 sec)

Not all attributes, but as least it show up the comments.

  • Related