查看 MySQL 数据库大小

查看 MySQL 所有数据库大小

  • SQL 查询语句如下:
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)',
SUM(truncate(DATA_FREE/1024/1024, 2)) AS '碎片占用(MB)'
FROM information_schema.tables
GROUP BY table_schema
ORDER BY SUM(data_length) DESC, SUM(index_length) DESC;
  • 查询结果如图所示
mysql_size.png

查看 MySQL 指定数据库大小

  • SQL 查询语句如下:
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)',
  truncate(DATA_FREE/1024/1024, 2) AS '碎片占用(MB)'
FROM information_schema.tables
WHERE table_schema=''
ORDER BY data_length DESC, index_length DESC;

你可能感兴趣的:(查看 MySQL 数据库大小)