当前位置:网站首页>MySQL的information_schema数据库
MySQL的information_schema数据库
2022-07-04 05:40:00 【易爻64】
前言
information_schema数据库,这个数据库中装的是mysql的元数据,包括数据库信息、数据库中表的信息等。所以要想查询数据库占用磁盘的空间大小可以通过对information_schema数据库进行操作。
主要表介绍
- schemata表:这个表里面主要是存储在mysql中的所有的数据库的信息
- tables表:这个表里存储了所有数据库中的表的信息,包括每个表有多少个列等信息。
- columns表:这个表存储了所有表中的表字段信息。
- statistics表:存储了表中索引的信息。
- user_privileges表:存储了用户的权限信息。
- schema_privileges表:存储了数据库权限。
- table_privileges表:存储了表的权限。
- column_privileges表:存储了列的权限信息。
- character_sets表:存储了mysql可以用的字符集的信息。
- collations表:提供各个字符集的对照信息。
- collation_character_set_applicability表:相当于collations表和character_sets表的前两个字段的一个对比,记录了字符集之间的对照信息。
- table_constraints表:这个表主要是用于记录表的描述存在约束的表和约束类型。
- key_column_usage表:记录具有约束的列。
- routines表:记录了存储过程和函数的信息,不包含自定义的过程或函数信息。
- views表:记录了视图信息,需要有show view权限。
- triggers表:存储了触发器的信息,需要有super权限。
应用示例
查询指定数据库下所有表的列信息(含索引)
select
tbst.table_schema,
tbst.table_name,
tbst.ordinal_position,
tbst.COLUMN_NAME,
tbst.COLUMN_TYPE,
tbst.DATA_TYPE,
tbst.IS_NULLABLE,
tbst.COLUMN_COMMENT,
tbix.INDEX_NAME
FROM
(SELECT
table_schema,
table_name,
ordinal_position,
COLUMN_NAME,
COLUMN_TYPE,
DATA_TYPE,
IS_NULLABLE,
COLUMN_COMMENT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_schema = '%s'
and TABLE_NAME not in('DATABASECHANGELOG', 'DATABASECHANGELOGLOCK')
) tbst
SELECT
table_schema,
table_name,
ordinal_position,
COLUMN_NAME,
COLUMN_TYPE,
DATA_TYPE,
IS_NULLABLE,
COLUMN_COMMENT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_schema = '%s'
and TABLE_NAME not in('DATABASECHANGELOG', 'DATABASECHANGELOGLOCK')
) tbst
left join
(
select
TABLE_SCHEMA,
TABLE_NAME,
INDEX_NAME,
GROUP_CONCAT(COLUMN_NAME) as INDEX_COLUMN
from
information_schema.statistics
where table_schema='%s'
and TABLE_NAME not in('DATABASECHANGELOG', 'DATABASECHANGELOGLOCK')
GROUP BY TABLE_NAME, INDEX_NAME
) tbix
ON tbst.table_name = tbix.TABLE_NAME
AND tbst.COLUMN_NAME = tbix.INDEX_COLUMN
AND tbst.table_schema = tbix. TABLE_SCHEMA
ORDER BY table_name, ordinal_position;
查询指定数据库下的所有表的引擎和字符集
select
TABLE_SCHEMA,
TABLE_NAME,
ENGINE,
TABLE_ROWS,
TABLE_COLLATION,
left(TABLE_COLLATION,7) as TABLE_COLLATION_SHORT
from information_schema.tables s
where table_schema='%s'
and TABLE_NAME not in('DATABASECHANGELOG', 'DATABASECHANGELOGLOCK');
要查询表所占的容量
是把表的数据和索引加起来就可以了, 上面获取的结果是以字节为单位的,可以通过除两个1024的到M为单位的结果。
select sum(DATA_LENGTH)+sum(INDEX_LENGTH) from information_schema.tables
where table_schema='数据库名';
参考文档
- https://www.cnblogs.com/diandiandidi/p/5582309.html
边栏推荐
- Programmers don't talk about morality, and use multithreading for Heisi's girlfriend
- Arc135 C (the proof is not very clear)
- left_ and_ right_ Net normal version
- HMS v1.0 appointment. PHP editid parameter SQL injection vulnerability (cve-2022-25491)
- BUU-Crypto-[HDCTF2019]basic rsa
- 1480. Dynamic sum of one-dimensional array
- Flask
- C # character similarity comparison general class
- (4) Canal multi instance use
- What are the reasons for the frequent high CPU of ECS?
猜你喜欢

How to expand all collapse panels

Take you to quickly learn how to use qsort and simulate qsort
![[microservice] Nacos cluster building and loading file configuration](/img/50/7af220c57a06eb186729c9882d9dab.png)
[microservice] Nacos cluster building and loading file configuration

Leakage detection relay jy82-2p

光模块字母含义及参数简称大全

VB. Net GIF (making and disassembling - optimizing code, class library - 5)

Configure cross compilation tool chain and environment variables

Kubernets first meeting
![How to use postman to realize simple interface Association [add, delete, modify and query]](/img/e9/bf89eacdebcf2ec84c8a08c28b9ca8.png)
How to use postman to realize simple interface Association [add, delete, modify and query]

The data mark is a piece of fat meat, and it is not only China Manfu technology that focuses on this meat
随机推荐
Descriptive analysis of data distribution characteristics (data exploration)
Excel comparator
BUU-Crypto-[HDCTF2019]basic rsa
2022 R2 mobile pressure vessel filling retraining question bank and answers
VB. Net simple processing pictures, black and white (class library - 7)
FreeRTOS 中 RISC-V-Qemu-virt_GCC 的 锁机制 分析
fastjson
Arc135 a (time complexity analysis)
1.1 history of Statistics
AWT常用组件、FileDialog文件选择框
LC周赛300
注释与注解
BUU-Pwn-test_ your_ nc
我的NVIDIA开发者之旅——优化显卡性能
Basic concept of bus
Design and implementation of redis 7.0 multi part AOF
JS get the attribute values nested in the object
509. Fibonacci number, all paths of climbing stairs, minimum cost of climbing stairs
[microservice] Nacos cluster building and loading file configuration
The data mark is a piece of fat meat, and it is not only China Manfu technology that focuses on this meat