当前位置:网站首页>MySQL information_ Schema database
MySQL information_ Schema database
2022-07-04 05:52:00 【Easy 64】
List of articles
Preface
information_schema database , This database contains mysql Metadata , Include database information 、 Information of tables in database, etc . Therefore, you can query the disk space occupied by the database by information_schema Database operation .
Introduction to main tables
- schemata surface : This table is mainly stored in mysql Information for all databases in
- tables surface : This table stores the information of all tables in the database , Include information such as how many columns each table has .
- columns surface : This table stores the table field information in all tables .
- statistics surface : Stored information of indexes in the table .
- user_privileges surface : The user's permission information is stored .
- schema_privileges surface : Database permissions stored .
- table_privileges surface : Stored table permissions .
- column_privileges surface : The permission information of the column is stored .
- character_sets surface : Store mysql Information about available character sets .
- collations surface : Provides cross reference information for each character set .
- collation_character_set_applicability surface : amount to collations Table and character_sets A comparison of the first two fields of the table , The cross reference information between character sets is recorded .
- table_constraints surface : This table is mainly used to record the tables with constraints and the constraint types .
- key_column_usage surface : Record columns with constraints .
- routines surface : Records information about stored procedures and functions , Does not contain custom procedure or function information .
- views surface : Recorded view information , Need to have show view jurisdiction .
- triggers surface : Stored trigger information , Need to have super jurisdiction .
Application example
Query the column information of all tables under the specified database ( Including index )
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;
Query the engine and character set of all tables under the specified database
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');
Capacity of the table to query
Add up the data and index of the table , The result obtained above is in bytes , You can divide by two 1024 To the M Results in units .
select sum(DATA_LENGTH)+sum(INDEX_LENGTH) from information_schema.tables
where table_schema=' Database name ';
Reference documents
- https://www.cnblogs.com/diandiandidi/p/5582309.html
边栏推荐
- buuctf-pwn write-ups (8)
- Supplement the JS of a video website to decrypt the video
- (4) Canal multi instance use
- JS string splicing enhancement
- Google Chrome browser will support the function of selecting text translation
- 724. 寻找数组的中心下标
- VB.net 调用FFmpeg简单处理视频(类库——6)
- Configure cross compilation tool chain and environment variables
- LC周赛300
- Talk about the SQL server version of DTM sub transaction barrier function
猜你喜欢

BUU-Pwn-test_ your_ nc

Uninstall Google drive hard drive - you must exit the program to uninstall

js arguments参数使用和详解

buuctf-pwn write-ups (8)

19. Framebuffer application programming

Component、Container容器常用API详解:Frame、Panel、ScrollPane

webrtc 快速搭建 视频通话 视频会议

Signification des lettres du module optique et abréviation des paramètres Daquan

A little understanding of GSLB (global server load balance) technology
![[QT] create mycombobox click event](/img/5a/ed17567a71f6737891fc7a8273df0a.png)
[QT] create mycombobox click event
随机推荐
ANSYS command
gslb(global server load balance)技术的一点理解
【微服务】Nacos集群搭建以及加载文件配置
How to solve the component conflicts caused by scrollbars in GridView
19.Frambuffer应用编程
Canoe panel learning video
APScheduler如何设置任务不并发(即第一个任务执行完再执行下一个)?
Leetcode 184 Employees with the highest wages in the Department (July 3, 2022)
Introduction To AMBA 简单理解
安装 Pytorch geometric
Basic concept of bus
C # character similarity comparison general class
transformer坑了多少算力
MySQL的information_schema数据库
C语言中的函数(详解)
JS how to convert seconds into hours, minutes and seconds display
云原生架构实战案例及优化解决方案
[high concurrency, high performance and high availability of massive data MySQL practice-7] - memory data drop disk
Design and implementation of tcp/ip series overview
JS string splicing