• mysql查看数据库大小以及使用情况

    发布时间:2022-07-08 11:59:27
    作者:ynkulusi
  • 转自:https://blog.csdn.net/jiahao1186/article/details/124723834
     

    一、用SQL命令查看Mysql数据库大小

    要想知道每个数据库的大小的话,步骤如下:

    1、进入information_schema 数据库(存放了其他的数据库的信息)

    use information_schema;

    2、查询所有数据的大小

    select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables;

    3、查看指定数据库的大小(查看数据库home的大小)

    select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='home';

    4、查看指定数据库的某个表的大小(查看数据库home中 members 表的大小)

    select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='home' and table_name='members';

    查看MySql数据空间使用情况:

    information_schema是MySQL的系统数据库,information_schema里的tables表存放了整个数据库各个表的使用情况。

    可以使用sql来统计出数据库的空间使用情况,相关字段:

    table_schema:数据库名

    table_name:表名

    table_rows:记录数

    data_length:数据大小

    index_length:索引大小
     

    二、使用空间

    1、统计表使用空间

    select concat(round(sum(data_length/1024/1024),2),'mb') as data from tables where table_schema='mydb' and table_name='mytable';
    
    | data |
    
    | 0.02mb |
    
    1 row in set (0.00 sec)

    2、统计数据库使用空间

    select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='mydb';
    
    | data |
     
    | 6.64MB |
     
    1 row in set (0.00 sec)

    3、统计所有数据使用空间

    select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables;
    
    | data |
     
    | 6.64MB |
     
    1 row in set (0.01 sec)
     
  • 分类:mysql
    标签: mysql
    评论数:0 阅读数:981