MySql用的少,不是很熟。有些SQL语句需要手写去查某些数据,基本也是参考网上的,做个记录,以免忘记。
1.查看数据库所有表的大小
select
table_schema as '数据库',
table_name as '表名',
table_rows as '行数',
truncate(data_length/1024/1024, 2) as '数据大小(MB)',
truncate(index_length/1024/1024, 2) as '索引大小(MB)'
from information_schema.tables
--where table_schema='mysql' --如果指定某个数据库 就 加个过滤
order by table_rows desc;
2.统计数据库的大小
select
table_schema as '数据库',
sum(table_rows) as '行数',
sum(truncate(data_length/1024/1024, 2)) as '数据大小(MB)',
sum(truncate(index_length/1024/1024, 2)) as '索引大小(MB)'
from information_schema.tables
group by table_schema
order by sum(table_rows) desc;
3.查看当前正在进行的进程
SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST;
未完待续