INFORMATION_SCHEMA.STATISTICS 统计 表 库 大小
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 统计 表 库 大小的更多相关文章
- 查看mysql库大小,表大小,索引大小
查看所有库的大小 mysql> use information_schema; Database changed mysql> selectconcat(round(sum(DATA_LE ...
- MySQL 库大小、表大小、索引大小查询命令
1.进去指定schema 数据库(存放了其他的数据库的信息) mysql> use information_schema; 2.查询所有数据的大小 mysql> sele ...
- MySQL查看库表的大小
MySQL数据库空间使用情况查询 如果想知道MySQL数据库中每个表占用的空间.表记录的行数的话,可以打开MySQL的 information_schema 数据库.在该库中有一个 TABLES 表, ...
- [转]【mysql监控】查看mysql库大小,表大小,索引大小
本文转自:http://blog.sina.com.cn/s/blog_4c197d420101fbl9.html 查看所有库的大小 mysql> use information_schema; ...
- SQL Server查看库、表占用空间大小
转自:https://blog.csdn.net/yenange/article/details/50493580 查询数据文件与日志文件占用情况,查看数据大小,查看库大小 1. 查看数据文件占用(权 ...
- 查看mysql库中所有表的大小和记录数
查看mysql库中所有表的大小和记录数 ,), 'MB') as total_size FROM information_schema.TABLES WHERE TABLE_SCHEMA='datab ...
- Atitit.mssql 数据库表记录数and 表体积大小统计
Atitit.mssql 数据库表记录数and 表体积大小统计 1. EXEC sp_MSforeachtable "EXECUTE sp_spaceused '?'&quo ...
- MySQL查看表占用空间大小(转)
MySQL查看表占用空间大小(转) //先进去MySQL自带管理库:information_schema //自己的数据库:dbwww58com_kuchecarlib //自己的表:t_carmod ...
- MySQL查看数据库表容量大小
本文介绍MySQL查看数据库表容量大小的命令语句,提供完整查询语句及实例,方便大家学习使用. 1.查看所有数据库容量大小 select table_schema as '数据库', sum(table ...
随机推荐
- pyqt加载图片
使用QPixmap可以加载图片,但是图片只能是标准二进制文件格式: bmp,gif,ico,jpeg,jpg,mng,pbm,pgm,png,ppm,svg,svgz,tga,tif,tiff,xbm ...
- hdu3948(后缀数组)
题意:给一串字符,需要你求不相同的回文子串个数....... 同ural1297,链接:http://www.cnblogs.com/ziyi--caolu/archive/2013/06/09/31 ...
- java POi excel 写入大批量数据
直接贴代码: package jp.co.misumi.mdm.batch.common.jobrunner; import java.io.File; import java.io.FileNotF ...
- Spring Mvc中DispatcherServlet和Servlet的区别小结
在web开发过程中开始接触的是servlet,用来处理用户请求.这几年随着spring 框架越来越成熟,几乎成了java web开发界的主流框架.既然这么受欢迎肯定有它的优点,spring框架在原来的 ...
- Android——Android Bundle详解(转)
Android Bundle详解 1 Bundle介绍 Bundle主要用于传递数据:它保存的数据,是以key-value(键值对)的形式存在的. 我们经常使用Bundle在Activity之间传递数 ...
- C#调用SQL Server有参的存储过程
一.使用SqlParameter的方式 代码: using System; using System.Collections.Generic; using System.ComponentModel; ...
- js 去掉数组中重复的对象
function deteleObject(obj) { // console.log(obj) var uniques = []; var stringify = {}; ; i < obj. ...
- div随页面滚动遇顶固定的两种方法(js&jQuery)
一.遇顶固定的例子 我一直以为是某个div或层随屏幕滚动,遇顶则固定,离开浏览器顶部又还原这样的例子其实不少,其实它的名字叫“层的智能浮动效果”.目前我们在国内的商业网站上就常常看到这样的效果了.例如 ...
- 使用Javascript实现随机字符串
方法一(其实是毫秒时间数字字符串): function randomString() { return '' + new Date().getTime(); } 方法二(随机字母数字字符串): var ...
- ActionContextCleanUp
ActionContextCleanUp作用 延长action中属性的生命周期,包括自定义属性,以便在jsp页面中进行访问,让actionContextcleanup过滤器来清除属性,不让acti ...