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. CControlLayer

    #ifndef __CONTROLLAYER_H__ #define __CONTROLLAYER_H__ #include "XWidget.h" class CMapDialo ...

  2. 0065 MyBatis一级缓存与二级缓存

    数据库中数据虽多,但访问频率却不同,有的数据1s内就会有多次访问,而有些数据几天都没人查询,这时候就可以将访问频率高的数据放到缓存中,就不用去数据库里取了,提高了效率还节约了数据库资源 MyBatis ...

  3. C语言 · 删除数组中的0元素

    算法提高 6-9删除数组中的0元素   时间限制:1.0s   内存限制:512.0MB      编写函数CompactIntegers,删除数组中所有值为0的元素,其后元素向数组首端移动.注意,C ...

  4. Android基础总结(三)SQLite,ListView,对话框

    测试 黑盒测试 测试逻辑业务 白盒测试 测试逻辑方法 根据测试粒度 方法测试:function test 单元测试:unit test 集成测试:integration test 系统测试:syste ...

  5. Istio流量管理实现机制深度解析

    https://zhaohuabing.com/post/2018-09-25-istio-traffic-management-impl-intro/TOC 前言 Pilot高层架构 统一的服务模型 ...

  6. thinkphp 命名规范

    目录和文件命名 目录和文件名采用 小写+下划线,并且以小写字母开头: 类库.函数文件统一以.php为后缀: 类的文件名均以命名空间定义,并且命名空间的路径和类库文件所在路径一致(包括大小写): 类名和 ...

  7. Javascript 你不知道的事

    NaN表示一个不能产生正常结果的运算结果.它不等于任何值,包括它自己.可以用isNaN(number)来检测. 同Java中的字符串一样,JS中的字符串是不可变的.也就是说一旦字符串被创建,就无法改变 ...

  8. JavaScript实现网页安全登录(转)

    现在很多商业网站的用户登录都是明码传输的,而一般用户又习惯于所有帐号使用相同的密码来保存,甚至很多人使用的密码和自己的银行帐号都一样哦!所 以嘛还是有一定的安全隐患的,YAHOO的免费邮箱登录使用了M ...

  9. OGNL支持各种纷繁复杂的表达式

    OGNL支持各种纷繁复杂的表达式.但是最最基本的表达式的原型,是将对象的引用值用点串联起来,从左到右,每一次表达式计算返回的结果成为当前对象,后面部分接着在当前对象上进行计算,一直到全部表达式计算完成 ...

  10. 【BZOJ】1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚(dp/线段树)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1672 dp很好想,但是是n^2的..但是可以水过..(5s啊..) 按左端点排序后 f[i]表示取第 ...