当前位置:网站首页>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
边栏推荐
- What are the reasons for the frequent high CPU of ECS?
- Principle and practice of common defects in RSA encryption application
- webrtc 快速搭建 视频通话 视频会议
- Design and implementation of tcp/ip series overview
- Google Chrome browser will support the function of selecting text translation
- Luogu deep foundation part 1 Introduction to language Chapter 5 array and data batch storage
- gslb(global server load balance)技术的一点理解
- What is MQ?
- Leetcode 184 Employees with the highest wages in the Department (July 3, 2022)
- BUU-Pwn-test_ your_ nc
猜你喜欢
Tf/pytorch/cafe-cv/nlp/ audio - practical demonstration of full ecosystem CPU deployment - Intel openvino tool suite course summary (Part 2)
C语言中的函数(详解)
[wechat applet] template and configuration (wxml, wxss, global and page configuration, network data request)
AWT介绍
Experience weekly report no. 102 (July 4, 2022)
One click filtering to select Baidu online disk files
How to expand all collapse panels
复合非线性反馈控制(二)
【微服务】Nacos集群搭建以及加载文件配置
Review | categories and mechanisms of action of covid-19 neutralizing antibodies and small molecule drugs
随机推荐
JS string splicing enhancement
left_and_right_net可解释性设计
js如何将秒转换成时分秒显示
SQL performance optimization skills
Install pytoch geometric
报错cvc-complex-type.2.4.a: 发现了以元素 ‘base-extension‘ 开头的无效内容。应以 ‘{layoutlib}‘ 之一开头。
[microservice] Nacos cluster building and loading file configuration
Steady! Huawei micro certification Huawei cloud computing service practice is stable!
Programmers don't talk about morality, and use multithreading for Heisi's girlfriend
Kubernets first meeting
Leakage detection relay jy82-2p
Excel 比较日器
input显示当前选择的图片
Halcon image calibration enables subsequent image processing to become the same as the template image
C # character similarity comparison general class
Overview of relevant subclasses of beanfactorypostprocessor and beanpostprocessor
Supplement the JS of a video website to decrypt the video
[QT] create mycombobox click event
如何判断数组中是否含有某个元素
[MySQL practice of massive data with high concurrency, high performance and high availability -8] - transaction isolation mechanism of InnoDB