有用的sql语句

  1. mysql中,查服务器上所有数据库分别占用了多少空间

SELECT

TABLE_SCHEMA AS '数据库名',

ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS '总大小 (MB)',

ROUND(SUM(data_length) / 1024 / 1024, 2) AS '数据大小 (MB)',

ROUND(SUM(index_length) / 1024 / 1024, 2) AS '索引大小 (MB)'

FROM

information_schema.TABLES

GROUP BY

TABLE_SCHEMA

ORDER BY

SUM(data_length + index_length) DESC;