当前位置:网站首页>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
边栏推荐
- The end of the Internet is rural revitalization
- Install pytoch geometric
- AWT常用组件、FileDialog文件选择框
- High performance parallel programming and optimization | lesson 02 homework at home
- 一键过滤选择百度网盘文件
- 如何判断数组中是否含有某个元素
- Recommended system 1 --- framework
- How to implement lazy loading in El select (with search function)
- VB.net 简单的处理图片,黑白(类库——7)
- Configure cross compilation tool chain and environment variables
猜你喜欢
随机推荐
LayoutManager布局管理器:FlowLayout、BorderLayout、GridLayout、GridBagLayout、CardLayout、BoxLayout
Introduction to AMBA
Upper computer software development - log information is stored in the database based on log4net
[Excel] 数据透视图
C language simple student management system (including source code)
buuctf-pwn write-ups (8)
[MySQL practice of massive data with high concurrency, high performance and high availability -8] - transaction isolation mechanism of InnoDB
Letter meaning and parameter abbreviation of optical module Daquan
云原生架构实战案例及优化解决方案
[microservice] Nacos cluster building and loading file configuration
如何判断数组中是否含有某个元素
px em rem的区别
C语言练习题(递归)
AWT常用组件、FileDialog文件选择框
JS flattened array of number shape structure
Use of hutool Pinyin tool
Zhanrui tankbang | jointly build, cooperate and win-win zhanrui core ecology
Easy change
1480. 一维数组的动态和
1.1 history of Statistics