查看所有数据库容量大小

  1. select
  2. table_schema as '数据库',
  3. sum(table_rows) as '记录数',
  4. sum(truncate(data_length/1024/1024, 2)) as '数据容量(MB)',
  5. sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)'
  6. from information_schema.tables
  7. where 1 = 1
  8. -- and table_schema IN ('jms')
  9. group by table_schema
  10. order by sum(data_length) desc, sum(index_length) desc;

查看所有数据库各表容量大小

  1. select
  2. table_schema as '数据库',
  3. table_name as '表名',
  4. table_rows as '记录数',
  5. truncate(data_length/1024/1024, 2) as '数据容量(MB)',
  6. truncate(index_length/1024/1024, 2) as '索引容量(MB)'
  7. from information_schema.tables
  8. where 1 = 1
  9. -- and table_schema IN ('jms')
  10. order by data_length desc, index_length desc;

查看所有数据库字段的基本信息

  1. SELECT
  2. -- T.TABLE_SCHEMA AS '库名',
  3. -- T.TABLE_NAME AS '表名',
  4. -- T.TABLE_COMMENT AS '表注释',
  5. (CASE WHEN C.ORDINAL_POSITION=1 THEN CONCAT(T.TABLE_SCHEMA ,'.', T.TABLE_NAME) ELSE '' END) AS '库名.表名',
  6. (CASE WHEN C.ORDINAL_POSITION=1 THEN T.TABLE_COMMENT ELSE '' END) AS '表注释',
  7. C.COLUMN_NAME AS '列名',
  8. C.COLUMN_COMMENT AS '列注释',
  9. C.ORDINAL_POSITION AS '列的排列顺序',
  10. C.COLUMN_DEFAULT AS '默认值',
  11. C.IS_NULLABLE AS '是否为空',
  12. C.DATA_TYPE AS '数据类型',
  13. C.CHARACTER_MAXIMUM_LENGTH AS '字符最大长度',
  14. C.NUMERIC_PRECISION AS '数值精度(最大位数)',
  15. C.NUMERIC_SCALE AS '小数精度',
  16. C.COLUMN_TYPE AS 列类型,
  17. C.COLUMN_KEY 'KEY',
  18. C.EXTRA AS '额外说明'
  19. FROM
  20. information_schema.`TABLES` T
  21. LEFT JOIN information_schema.`COLUMNS` C ON T.TABLE_NAME = C.TABLE_NAME
  22. AND T.TABLE_SCHEMA = C.TABLE_SCHEMA
  23. WHERE 1 = 1
  24. -- AND T.TABLE_SCHEMA IN ('jms')
  25. ORDER BY
  26. C.TABLE_NAME,
  27. C.ORDINAL_POSITION;