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 ...
随机推荐
- location 禁止多目录
[root@web01 default]# mkdir cron templates [root@web01 default]# tree . ├── cron └── templates direc ...
- cnblogs博客迁移到hexo
cnblogs博客备份 备份地址:https://i.cnblogs.com/BlogBackup.aspx?type=1 备份文件为xml格式,打开备份文件,如下所示: <?xml versi ...
- swift 类型.
swift 类型 变量声明 用let来声明常量,用var来声明变量 可以在一行中声明多个常量或者多个变量,用逗号隔开 var x = 0.0, y = 0.0, z = 0.0 类型安全 Swift ...
- 页面跳转时候拼接在url后面的多个 参数获取
function GetRequest() { var url = location.search; var theRequest = new Object(); if (url.indexOf(&q ...
- Linux系统(Ubuntu/Debian/RedHat/CentOS)超级简单的samba配置文件smb.conf
1.超简单的smb.conf 该配置文件对Ubuntu和CentOS都好用. #============== Global Settings ============== [global] ## Br ...
- FreeRtos——多任务
官方资料整理测试: 多任务和单任务几乎没有差别.只用多创建一个或多个任务,其他地方和单任务时相同. static void AppTaskCreate(void) { xTaskCreate(vTas ...
- linux回调函数的使用
#include<stdio.h> #include<pthread.h> #include<unistd.h> pthread_mutex_t mutex; pt ...
- oozie调度hive脚本demo
1. 环境配置 2. 脚本配置 3. 执行job 4. 查看结果 待发布 ..
- DP - 字符混编
字符混编 Problem's Link ---------------------------------------------------------------------------- Mea ...
- malloc 函数本身并不识别要申请的内存是什么类型
malloc 函数本身并不识别要申请的内存是什么类型,它只关心内存的总字节数.我 们通常记不住 int, float 等数据类型的变量的确切字节数. 例如 int 变量在 16 位系统 下是 2 个字 ...