INFORMATION_SCHEMA

MySQL :: MySQL 5.5 Reference Manual :: 21 INFORMATION_SCHEMA Tables

https://dev.mysql.com/doc/refman/5.5/en/information-schema.html

INFORMATION_SCHEMA Usage Notes

INFORMATION_SCHEMA is a database within each MySQL instance, the place that stores information about all the other databases that the MySQL server maintains. The INFORMATION_SCHEMA database contains several read-only tables. They are actually views, not base tables, so there are no files associated with them, and you cannot set triggers on them. Also, there is no database directory with that name.

Although you can select INFORMATION_SCHEMA as the default database with a USE statement, you can only read the contents of tables, not perform INSERT,UPDATE, or DELETE operations on them.

问题来源, 删除索引前的存在性检测。

http://dev.mysql.com/doc/refman/5.7/en/statistics-table.html

http://m.blog.csdn.net/lilin_esri/article/details/69944346

查询所有的数据库占用磁盘空间大小

SELECT
TABLE_SCHEMA,
CONCAT(
TRUNCATE (
SUM(DATA_LENGTH) / 1024 / 1024,
2
),
' MB'
) AS data_size,
concat(
TRUNCATE (
SUM(DATA_LENGTH) / 1024 / 1024,
2
),
'MB'
) AS index_size
FROM
information_schema. TABLES
GROUP BY
TABLE_SCHEMA
ORDER BY
DATA_LENGTH DESC;

SELECT
*
FROM
information_schema. TABLES;

查询单个数据库各个表占用磁盘空间大小

SELECT
TABLE_NAME,
CONCAT(
TRUNCATE (DATA_LENGTH / 1024 / 1024, 2),
' MB'
) AS data_size,
CONCAT(
TRUNCATE (INDEX_LENGTH / 1024 / 1024, 2),
' MB'
) AS index_size
FROM
information_schema. TABLES
WHERE
TABLE_SCHEMA = 'mydb'
GROUP BY
TABLE_NAME
ORDER BY
DATA_LENGTH DESC;

统计  表 库  大小

[root@d mysql]# bin/mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.15 Source distribution Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sem |
| sem_bak |
| sys |
+--------------------+
6 rows in set (0.00 sec) mysql> desc information_schema.tables;
+-----------------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+---------------------+------+-----+---------+-------+
| TABLE_CATALOG | varchar(512) | NO | | | |
| TABLE_SCHEMA | varchar(64) | NO | | | |
| TABLE_NAME | varchar(64) | NO | | | |
| TABLE_TYPE | varchar(64) | NO | | | |
| ENGINE | varchar(64) | YES | | NULL | |
| VERSION | bigint(21) unsigned | YES | | NULL | |
| ROW_FORMAT | varchar(10) | YES | | NULL | |
| TABLE_ROWS | bigint(21) unsigned | YES | | NULL | |
| AVG_ROW_LENGTH | bigint(21) unsigned | YES | | NULL | |
| DATA_LENGTH | bigint(21) unsigned | YES | | NULL | |
| MAX_DATA_LENGTH | bigint(21) unsigned | YES | | NULL | |
| INDEX_LENGTH | bigint(21) unsigned | YES | | NULL | |
| DATA_FREE | bigint(21) unsigned | YES | | NULL | |
| AUTO_INCREMENT | bigint(21) unsigned | YES | | NULL | |
| CREATE_TIME | datetime | YES | | NULL | |
| UPDATE_TIME | datetime | YES | | NULL | |
| CHECK_TIME | datetime | YES | | NULL | |
| TABLE_COLLATION | varchar(32) | YES | | NULL | |
| CHECKSUM | bigint(21) unsigned | YES | | NULL | |
| CREATE_OPTIONS | varchar(255) | YES | | NULL | |
| TABLE_COMMENT | varchar(2048) | NO | | | |
+-----------------+---------------------+------+-----+---------+-------+
21 rows in set (0.00 sec) mysql> select * from information_schema.tables limit 5;
+---------------+--------------------+---------------------------------------+-------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+----------------+---------------+
| TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | TABLE_TYPE | ENGINE | VERSION | ROW_FORMAT | TABLE_ROWS | AVG_ROW_LENGTH | DATA_LENGTH | MAX_DATA_LENGTH | INDEX_LENGTH | DATA_FREE | AUTO_INCREMENT | CREATE_TIME | UPDATE_TIME | CHECK_TIME | TABLE_COLLATION | CHECKSUM | CREATE_OPTIONS | TABLE_COMMENT |
+---------------+--------------------+---------------------------------------+-------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+----------------+---------------+
| def | information_schema | CHARACTER_SETS | SYSTEM VIEW | MEMORY | 10 | Fixed | NULL | 384 | 0 | 16434816 | 0 | 0 | NULL | 2018-11-29 14:37:45 | NULL | NULL | utf8_general_ci | NULL | max_rows=43690 | |
| def | information_schema | COLLATIONS | SYSTEM VIEW | MEMORY | 10 | Fixed | NULL | 231 | 0 | 16704765 | 0 | 0 | NULL | 2018-11-29 14:37:45 | NULL | NULL | utf8_general_ci | NULL | max_rows=72628 | |
| def | information_schema | COLLATION_CHARACTER_SET_APPLICABILITY | SYSTEM VIEW | MEMORY | 10 | Fixed | NULL | 195 | 0 | 16357770 | 0 | 0 | NULL | 2018-11-29 14:37:45 | NULL | NULL | utf8_general_ci | NULL | max_rows=86037 | |
| def | information_schema | COLUMNS | SYSTEM VIEW | InnoDB | 10 | Dynamic | NULL | 0 | 16384 | 0 | 0 | 8388608 | NULL | NULL | NULL | NULL | utf8_general_ci | NULL | max_rows=2789 | |
| def | information_schema | COLUMN_PRIVILEGES | SYSTEM VIEW | MEMORY | 10 | Fixed | NULL | 2565 | 0 | 16757145 | 0 | 0 | NULL | 2018-11-29 14:37:45 | NULL | NULL | utf8_general_ci | NULL | max_rows=6540 | |
+---------------+--------------------+---------------------------------------+-------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+----------------+---------------+
5 rows in set (0.03 sec) mysql> select distinct(TABLE_CATALOG) from information_schema.tables ;
+---------------+
| TABLE_CATALOG |
+---------------+
| def |
+---------------+
1 row in set (0.00 sec) mysql> select distinct(TABLE_SCHEMA) from information_schema.tables ;
+--------------------+
| TABLE_SCHEMA |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sem |
| sem_bak |
| sys |
+--------------------+
6 rows in set (0.01 sec) mysql> select table_name, (data_length/1024/1024) as data_mb , (index_length/1024/1024) as index_mb, ((data_length+index_length)/1024/1024) as all_mb, table_rows from tables where TABLE_SCHEMA = 'sem';
ERROR 1046 (3D000): No database selected
mysql> select table_name, (data_length/1024/1024) as data_mb , (index_length/1024/1024) as index_mb, ((data_length+index_length)/1024/1024) as all_mb, table_rows from information_schema.tables where TABLE_SCHEMA = 'sem';
+-------------+----------------+--------------+----------------+------------+
| table_name | data_mb | index_mb | all_mb | table_rows |
+-------------+----------------+--------------+----------------+------------+
| article | 455.90625000 | 0.00000000 | 455.90625000 | 5827967 |
| cinfo | 0.01562500 | 0.01562500 | 0.03125000 | 0 |
| cinfo1 | 496.90625000 | 145.70312500 | 642.60937500 | 9256895 |
| cinfo2 | 471.89062500 | 125.70312500 | 597.59375000 | 8754276 |
| cinfo3 | 109.60937500 | 31.57812500 | 141.18750000 | 2268454 |
| cinfoview | NULL | NULL | NULL | NULL |
| cinfoview1 | NULL | NULL | NULL | NULL |
| cinfoview2 | NULL | NULL | NULL | NULL |
| cinfoview3 | NULL | NULL | NULL | NULL |
| content | 0.01562500 | 0.00000000 | 0.01562500 | 0 |
| content1 | 24400.00000000 | 139.70312500 | 24539.70312500 | 7781986 |
| content2 | 26372.00000000 | 125.70312500 | 26497.70312500 | 7713312 |
| content3 | 6749.00000000 | 31.57812500 | 6780.57812500 | 1855395 |
| info | 443.87500000 | 0.00000000 | 443.87500000 | 8864137 |
| info1 | 486.89062500 | 0.00000000 | 486.89062500 | 9513996 |
| info2 | 320.79687500 | 0.00000000 | 320.79687500 | 7274232 |
| info_c | 0.01562500 | 0.00000000 | 0.01562500 | 0 |
| info_c1 | 0.01562500 | 0.00000000 | 0.01562500 | 0 |
| info_c2 | 0.01562500 | 0.00000000 | 0.01562500 | 0 |
| infoview | NULL | NULL | NULL | NULL |
| infoview1 | NULL | NULL | NULL | NULL |
| infoview2 | NULL | NULL | NULL | NULL |
| semtags | 0.10937500 | 0.01562500 | 0.12500000 | 50 |
| tags | 553.98437500 | 0.00000000 | 553.98437500 | 9242997 |
| tags1 | 504.95312500 | 0.00000000 | 504.95312500 | 8448984 |
| tags2 | 526.96875000 | 0.00000000 | 526.96875000 | 8797155 |
| tags3 | 131.64062500 | 31.57812500 | 163.21875000 | 2243969 |
| tags_201703 | 15.51562500 | 0.10937500 | 15.62500000 | 5374 |
| tags_201704 | 0.01562500 | 0.01562500 | 0.03125000 | 0 |
| tags_201705 | 0.01562500 | 0.01562500 | 0.03125000 | 0 |
| tags_201706 | 0.01562500 | 0.01562500 | 0.03125000 | 0 |
| tags_201707 | 0.01562500 | 0.01562500 | 0.03125000 | 0 |
+-------------+----------------+--------------+----------------+------------+
32 rows in set (0.00 sec) mysql> select table_name, (data_length/1024/1024) as data_mb , (index_length/1024/1024) as index_mb, ((data_length+index_length)/1024/1024) as all_mb, table_rows from information_schema.tables where TABLE_SCHEMA = 'sem_bak';
+------------+------------+------------+------------+------------+
| table_name | data_mb | index_mb | all_mb | table_rows |
+------------+------------+------------+------------+------------+
| info1 | 0.01562500 | 0.00000000 | 0.01562500 | 2 |
| semtags | 0.01562500 | 0.01562500 | 0.03125000 | 4 |
+------------+------------+------------+------------+------------+
2 rows in set (0.00 sec) mysql> select table_schema, sum(data_length+index_length)/1024/1024 as total_mb, sum(data_length)/1024/1024 as data_mb, sum(index_length)/1024/1024 as index_mb, count(*) as tables, curdate() as today from information_schema.tables group by table_schema;
+--------------------+----------------+----------------+--------------+--------+------------+
| table_schema | total_mb | data_mb | index_mb | tables | today |
+--------------------+----------------+----------------+--------------+--------+------------+
| information_schema | 0.15625000 | 0.15625000 | 0.00000000 | 61 | 2018-11-29 |
| mysql | 2.42948151 | 2.21561432 | 0.21386719 | 31 | 2018-11-29 |
| performance_schema | 0.00000000 | 0.00000000 | 0.00000000 | 87 | 2018-11-29 |
| sem | 62671.93750000 | 62040.18750000 | 631.75000000 | 32 | 2018-11-29 |
| sem_bak | 0.04687500 | 0.03125000 | 0.01562500 | 2 | 2018-11-29 |
| sys | 0.01562500 | 0.01562500 | 0.00000000 | 101 | 2018-11-29 |
+--------------------+----------------+----------------+--------------+--------+------------+
6 rows in set (0.04 sec) mysql>

  

INFORMATION_SCHEMA.STATISTICS 统计 表 库 大小的更多相关文章

  1. 查看mysql库大小,表大小,索引大小

    查看所有库的大小 mysql> use information_schema; Database changed mysql> selectconcat(round(sum(DATA_LE ...

  2. MySQL 库大小、表大小、索引大小查询命令

    1.进去指定schema 数据库(存放了其他的数据库的信息)     mysql> use information_schema; 2.查询所有数据的大小      mysql> sele ...

  3. MySQL查看库表的大小

    MySQL数据库空间使用情况查询 如果想知道MySQL数据库中每个表占用的空间.表记录的行数的话,可以打开MySQL的 information_schema 数据库.在该库中有一个 TABLES 表, ...

  4. [转]【mysql监控】查看mysql库大小,表大小,索引大小

    本文转自:http://blog.sina.com.cn/s/blog_4c197d420101fbl9.html 查看所有库的大小 mysql> use information_schema; ...

  5. SQL Server查看库、表占用空间大小

    转自:https://blog.csdn.net/yenange/article/details/50493580 查询数据文件与日志文件占用情况,查看数据大小,查看库大小 1. 查看数据文件占用(权 ...

  6. 查看mysql库中所有表的大小和记录数

    查看mysql库中所有表的大小和记录数 ,), 'MB') as total_size FROM information_schema.TABLES WHERE TABLE_SCHEMA='datab ...

  7. Atitit.mssql 数据库表记录数and 表体积大小统计

    Atitit.mssql 数据库表记录数and 表体积大小统计 1. EXEC   sp_MSforeachtable   "EXECUTE   sp_spaceused   '?'&quo ...

  8. MySQL查看表占用空间大小(转)

    MySQL查看表占用空间大小(转) //先进去MySQL自带管理库:information_schema //自己的数据库:dbwww58com_kuchecarlib //自己的表:t_carmod ...

  9. MySQL查看数据库表容量大小

    本文介绍MySQL查看数据库表容量大小的命令语句,提供完整查询语句及实例,方便大家学习使用. 1.查看所有数据库容量大小 select table_schema as '数据库', sum(table ...

随机推荐

  1. 禁止Chrome浏览器自动升级

    对于我们测试人员来说,浏览器自动升级是非常可怕的,浏览器的升级会导致出现各种bug,比如我们常用的Selenium,如果Chrome浏览器自动升级就会导致脚本出错,无法打开浏览器等等情况,对于这种情况 ...

  2. Debian7/8安装最新的nginx稳定版本

    我们知道,通过 apt-get install nginx 就可以安装上nginx,可惜这样安装的nginx版本都有些旧,就连最新的Debian 8.0 默认安装的仍然是1.6.2,更别说 Debia ...

  3. BZOJ 3922 - Karin的弹幕

    Karin的弹幕 Problem's Link ---------------------------------------------------------------------------- ...

  4. 时钟.html

    <!DOCTYPE html><html charset="utf-8"> <head> <title>时钟</title&g ...

  5. 解决mac休眠睡眠异常耗电方法

    备忘

  6. Ribbon,主要提供客户侧的软件负载均衡算法。

    Ribbon Ribbon,主要提供客户侧的软件负载均衡算法.Ribbon客户端组件提供一系列完善的配置选项,比如连接超时.重试.重试算法等.Ribbon内置可插拔.可定制的负载均衡组件.下面是用到的 ...

  7. gsoap 学习 1-自己定义接口生成头文件

    接口头文件的格式在向导中没有看到明确的说明性的内容,但通过看开发包中示例程序中头文件定义和通过wsdl生成的头文件的内容,可以发现,头文件中都会出现以下几行信息 //gsoap ns service ...

  8. 【BZOJ】1005: [HNOI2008]明明的烦恼(prufer编码+特殊的技巧)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1005 这里讲得挺清楚的:http://www.cnblogs.com/zhj5chengfeng/p ...

  9. .bss,.data,.text,.rodata

    那天工作时候发现build的时候发现问题, 问题内容是:.text的空间太小了. 我一直以为写代码,就真是弄懂代码怎么写,式样书怎么写,或者弄懂代码的问题所在, 没有想到在build的时候出现问题.结 ...

  10. Docker 如何把镜像上传到docker hub

    1 首先你得准备一个hub 的帐号, 去 https://hub.docker.com 注册吧! 2 在hub那里新建一个仓库, 这个就类似于github那边的..create ---> cre ...