问题

软件 >> MySQL
Questions in category: MySQL (MySQL).

[mysql] information_schema 数据库

Posted by haifeng on 2020-10-13 11:26:26 last update 2020-10-13 11:26:26 | Answers (0) | 收藏


information_schema 数据库中存储了许多动态的信息.

其中有一张表叫 COLUMNS.

执行 select * from  information_schema.COLUMNS; 将输出很多行

它记录了所有数据库中的列的名称等属性

mysql> select * from  COLUMNS;

...

1883 rows in set

--------------------------------------------

举个例子:

 

mysql> use information_schema;
Database changed
mysql> select * from  COLUMNS where table_name='ships';
+---------------+-----------------+------------+-------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+---------------+--------------------+--------------------+----------------+-------------+------------+-------+---------------------------------+----------------+
| TABLE_CATALOG | TABLE_SCHEMA    | TABLE_NAME | COLUMN_NAME | ORDINAL_POSITION | COLUMN_DEFAULT | IS_NULLABLE | DATA_TYPE | CHARACTER_MAXIMUM_LENGTH | CHARACTER_OCTET_LENGTH | NUMERIC_PRECISION | NUMERIC_SCALE | DATETIME_PRECISION | CHARACTER_SET_NAME | COLLATION_NAME | COLUMN_TYPE | COLUMN_KEY | EXTRA | PRIVILEGES                      | COLUMN_COMMENT |
+---------------+-----------------+------------+-------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+---------------+--------------------+--------------------+----------------+-------------+------------+-------+---------------------------------+----------------+
| def           | test_shipsinww2 | ships      | name        |                1 | NULL           | YES         | varchar   |                       20 |                     40 |              NULL |          NULL |               NULL | gbk                | gbk_chinese_ci | varchar(20) |            |       | select,insert,update,references |                |
| def           | test_shipsinww2 | ships      | class       |                2 | NULL           | YES         | varchar   |                       20 |                     40 |              NULL |          NULL |               NULL | gbk                | gbk_chinese_ci | varchar(20) |            |       | select,insert,update,references |                |
| def           | test_shipsinww2 | ships      | launched    |                3 | NULL           | YES         | year      |                     NULL |                   NULL |              NULL |          NULL |               NULL | NULL               | NULL           | year(4)     |            |       | select,insert,update,references |                |
+---------------+-----------------+------------+-------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+---------------+--------------------+--------------------+----------------+-------------+------------+-------+---------------------------------+----------------+
3 rows in set (0.04 sec)