当前位置:网站首页>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
边栏推荐
- left_ and_ right_ Net interpretable design
- One click filtering to select Baidu online disk files
- How to configure static IP for Kali virtual machine
- Uninstall Google drive hard drive - you must exit the program to uninstall
- FreeRTOS 中 RISC-V-Qemu-virt_GCC 的 锁机制 分析
- LC周赛300
- Win10 clear quick access - leave no trace
- [microservice] Nacos cluster building and loading file configuration
- webrtc 快速搭建 视频通话 视频会议
- 报错cvc-complex-type.2.4.a: 发现了以元素 ‘base-extension‘ 开头的无效内容。应以 ‘{layoutlib}‘ 之一开头。
猜你喜欢
BeanFactoryPostProcessor 与 BeanPostProcessor 相关子类概述
Win10 clear quick access - leave no trace
BUU-Crypto-[GXYCTF2019]CheckIn
19.Frambuffer应用编程
How to use postman to realize simple interface Association [add, delete, modify and query]
[high concurrency, high performance and high availability of massive data MySQL practice-7] - memory data drop disk
接地继电器DD-1/60
HMS v1.0 appointment.php editid参数 SQL注入漏洞(CVE-2022-25491)
win10清除快速访问-不留下痕迹
Configure cross compilation tool chain and environment variables
随机推荐
509. Fibonacci number, all paths of climbing stairs, minimum cost of climbing stairs
transformer坑了多少算力
Flask
APScheduler如何设置任务不并发(即第一个任务执行完再执行下一个)?
Luogu deep foundation part 1 Introduction to language Chapter 5 array and data batch storage
Google Chrome browser will support the function of selecting text translation
19.Frambuffer应用编程
How to configure static IP for Kali virtual machine
光模块字母含义及参数简称大全
Win10 clear quick access - leave no trace
Descriptive analysis of data distribution characteristics (data exploration)
Flask
Use of hutool Pinyin tool
Solar insect killing system based on single chip microcomputer
简易零钱通
Zhanrui tankbang | jointly build, cooperate and win-win zhanrui core ecology
How to use postman to realize simple interface Association [add, delete, modify and query]
Excel comparator
Design and implementation of tcp/ip series overview
AWT介绍