MySQL--查询表统计信息
=============================================================
show table status like '%waybill5%' \G
## 查看非InnoDB引擎表
SELECT
TABLE_SCHEMA AS database_name,
TABLE_NAME AS table_name,
TABLE_ROWS AS table_rows,
ENGINE AS table_engine,
ROUND((DATA_LENGTH)/1024.0/1024, 2) AS Data_MB,
ROUND((INDEX_LENGTH)/1024.0/1024, 2) AS Index_MB,
ROUND((DATA_LENGTH+INDEX_LENGTH)/1024.0/1024, 2) AS Total_MB,
ROUND((DATA_FREE)/1024.0/1024, 2) AS Free_MB
FROM information_schema.`TABLES` AS T1
WHERE T1.`TABLE_SCHEMA` NOT IN('performance_schema','mysql','information_schema','sys')
AND T1.`ENGINE` NOT IN ('innodb');
==============================================================
查看数据表较大的表
## 查看数据表量较大的表
SELECT
TABLE_SCHEMA AS database_name,
TABLE_NAME AS table_name,
TABLE_ROWS AS table_rows,
ENGINE AS table_engine,
ROUND((DATA_LENGTH)/1024.0/1024, 2) AS Data_MB,
ROUND((INDEX_LENGTH)/1024.0/1024, 2) AS Index_MB,
ROUND((DATA_LENGTH+INDEX_LENGTH)/1024.0/1024, 2) AS Total_MB,
ROUND((DATA_FREE)/1024.0/1024, 2) AS Free_MB
FROM information_schema.`TABLES` AS T1
WHERE T1.`TABLE_SCHEMA` NOT IN('performance_schema','mysql','information_schema')
ORDER BY T1.`TABLE_ROWS` DESC
LIMIT 10; ## 查看数据表空间较大的表
SELECT
TABLE_SCHEMA AS database_name,
TABLE_NAME AS table_name,
TABLE_ROWS AS table_rows,
ENGINE AS table_engine,
ROUND((DATA_LENGTH)/1024.0/1024, 2) AS Data_MB,
ROUND((INDEX_LENGTH)/1024.0/1024, 2) AS Index_MB,
ROUND((DATA_LENGTH+INDEX_LENGTH)/1024.0/1024, 2) AS Total_MB,
ROUND((DATA_FREE)/1024.0/1024, 2) AS Free_MB
FROM information_schema.`TABLES` AS T1
WHERE T1.`TABLE_SCHEMA` NOT IN('performance_schema','mysql','information_schema')
ORDER BY
ROUND((DATA_LENGTH+INDEX_LENGTH)/1024.0/1024, 2)
DESC LIMIT 10;
==============================================================
查看碎片较多的表
## 查看碎片较多的表
SELECT
TABLE_SCHEMA AS database_name,
TABLE_NAME AS table_name,
TABLE_ROWS AS table_rows,
ENGINE AS table_engine,
ROUND((DATA_LENGTH)/1024.0/1024, 2) AS Data_MB,
ROUND((INDEX_LENGTH)/1024.0/1024, 2) AS Index_MB,
ROUND((DATA_LENGTH+INDEX_LENGTH)/1024.0/1024, 2) AS Total_MB,
ROUND((DATA_FREE)/1024.0/1024, 2) AS Free_MB,
ROUND(ROUND((DATA_FREE)/1024.0/1024, 2) /ROUND((DATA_LENGTH+INDEX_LENGTH)/1024.0/1024, 2)*100,2)AS Free_Percent
FROM information_schema.`TABLES` AS T1
WHERE T1.`TABLE_SCHEMA` NOT IN('performance_schema','mysql','information_schema')
AND ROUND(ROUND((DATA_FREE)/1024.0/1024, 2) /ROUND((DATA_LENGTH+INDEX_LENGTH)/1024.0/1024, 2)*100,2) >10
AND ROUND((DATA_FREE)/1024.0/1024, 2)>100
ORDER BY ROUND(ROUND((DATA_FREE)/1024.0/1024, 2) /ROUND((DATA_LENGTH+INDEX_LENGTH)/1024.0/1024, 2)*100,2) DESC
LIMIT 10;
==============================================================
查看表当前自增值
## 查看表自增值
SELECT
T2.TABLE_SCHEMA,
T2.TABLE_NAME,
T1.COLUMN_NAME,
T1.COLUMN_TYPE,
T2.AUTO_INCREMENT
FROM information_schema.columns AS T1
INNER JOIN information_schema.tables AS T2
ON T1.TABLE_SCHEMA=T2.TABLE_SCHEMA
AND T1.TABLE_NAME=T2.TABLE_NAME
WHERE T1.EXTRA='auto_increment'
AND T1.DATA_TYPE NOT LIKE '%bigint%'
ORDER BY T2.AUTO_INCREMENT DESC
LIMIT 100;
==============================================================
查看无主键表
## 查看无主键表
SELECT
TABLE_SCHEMA AS database_name,
TABLE_NAME AS table_name,
TABLE_ROWS AS table_rows,
ENGINE AS table_engine,
ROUND((DATA_LENGTH)/1024.0/1024, 2) AS Data_MB,
ROUND((INDEX_LENGTH)/1024.0/1024, 2) AS Index_MB,
ROUND((DATA_LENGTH+INDEX_LENGTH)/1024.0/1024, 2) AS Total_MB,
ROUND((DATA_FREE)/1024.0/1024, 2) AS Free_MB
FROM information_schema.tables
WHERE (table_schema, table_name) NOT IN (
SELECT DISTINCT table_schema, table_name
FROM information_schema.columns
WHERE COLUMN_KEY = 'PRI'
)
AND table_schema NOT IN ('sys', 'mysql', 'information_schema', 'performance_schema');
MySQL--查询表统计信息的更多相关文章
- Atitit mysql数据库统计信息
Atitit mysql数据库统计信息 SELECT table_name, table_rows, index_length, data_length, auto_increment, create ...
- MySQL的统计信息学习总结
统计信息概念 MySQL统计信息是指数据库通过采样.统计出来的表.索引的相关信息,例如,表的记录数.聚集索引page个数.字段的Cardinality.....MySQL在生成执行计划时,需要根据索引 ...
- mysql收集统计信息
一.手动 执行Analyze table innodb和myisam存储引擎都可以通过执行“Analyze table tablename”来收集表的统计信息,除非执行计划不准确,否则不要轻易执行该 ...
- MySQL索引统计信息更新相关的参数
MySQL统计信息相关的参数: 1. innodb_stats_on_metadata(是否自动更新统计信息),MySQL 5.7中默认为关闭状态 仅在统计信息配置为非持久化的时候生效. 也就是说在i ...
- MySql 查询表结构信息
select Column_name as 列名,is_nullable as 是否可为空,data_type as 数据类型,column_default as 默认值,case when colu ...
- MySQL 8.0 中统计信息直方图的尝试
直方图是表上某个字段在按照一定百分比和规律采样后的数据分布的一种描述,最重要的作用之一就是根据查询条件,预估符合条件的数据量,为sql执行计划的生成提供重要的依据在MySQL 8.0之前的版本中,My ...
- mysql-5.7 持久化统计信息详解
一.持久化统计信息的意义: 统计信息用于指导mysql生成执行计划,执行计划的准确与否直接影响到SQL的执行效率:如果mysql一重启 之前的统计信息就没有了,那么当SQL语句来临时,那么mysql就 ...
- MySQL InnoDB配置统计信息
MySQL InnoDB配置统计信息 1. 配置持久化(Persistent)统计信息参数 1.1 配置自动触发更新统计信息参数 1.2 配置每张表的统计参数 1.3 配置InnoDB优化器统计信息的 ...
- MySQL统计信息以及执行计划预估方式初探
数据库中的统计信息在不同(精确)程度上描述了表中数据的分布情况,执行计划通过统计信息获取符合查询条件的数据大小(行数),来指导执行计划的生成.在以Oracle和SQLServer为代表的商业数据库,和 ...
- sql点滴—mysql中查询表的信息
mysql中查询表的信息 查询mysql表字段信息的sql语句 SHOW DATABASES //列出 MySQL Server 数据库. SHOW TABLES [FROM db_name] //列 ...
随机推荐
- 用MVVM模式开发中遇到的零散问题总结(1)
https://www.cnblogs.com/tong-tong/archive/2011/11/28/2250948.html
- PC端,移动端分离,如何结合??
<script type="text/javascript"> function mobile_device_detect(url) { var thisOS = na ...
- 『TensorFlow』DCGAN生成动漫人物头像_下
『TensorFlow』以GAN为例的神经网络类范式 『cs231n』通过代码理解gan网络&tensorflow共享变量机制_上 『TensorFlow』通过代码理解gan网络_中 一.计算 ...
- hdu多校(二) 1004 1007 1010
Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- 多线程私有数据pthread_key_create
参照:http://blog.csdn.net/xiaohuangcat/article/details/18267561 在多线程的环境下,进程内的所有线程共享进程的数据空间.因此全局变量为所有线程 ...
- Adaboost入门教程——最通俗易懂的原理介绍(图文实例)
https://blog.csdn.net/px_528/article/details/72963977 写在前面 说到Adaboost,公式与代码网上到处都有,<统计学习方法>里面有详 ...
- .net 中struct(结构)和class(类)的区别
1.struct 结构与class(类)的区别 1)struct是值类型,class是对象类型 2)struct不能被继承,class可以被继承 3)struct默认访问权限是public,而clas ...
- sqlite 查询数据库中所有的表名,判断某表是否存在,将某列所有数值去重后获得数量
1.列出当前db文件中所有的表的表名 SQL语句:SELECT * FROM sqlite_master WHERE type='table'; 结构如下: 注:网上有人说可以带上db文件的名称,如: ...
- learning scala 变量
scala 变量: val : 声明时,必须被初始化,不能再重新赋值. scala> test = "only1"<console>:11: error: not ...
- bzoj1626
题解: 简单最小生成树 x,y都要double 我也不知道为什么 代码: #include<bits/stdc++.h> using namespace std; ; int n,m,f[ ...