How can you determine how much disk space a particular MySQL table is taking up?

前端 未结 8 478
死守一世寂寞
死守一世寂寞 2020-11-30 16:20

Is there a quick way to determine how much disk space a particular MySQL table is taking up? The table may be MyISAM or Innodb.

相关标签:
8条回答
  • 2020-11-30 16:50

    In linux with mysql installed by default:

    [you@yourbox]$ ls -lha /var/lib/mysql/<databasename>
    

    based on NIXCRAFT's mysql db location

    0 讨论(0)
  • 2020-11-30 16:53

    You could perhaps look at the size of the files...

    Each table is stored in a couple of separate files inside a folder that is named whatever you called your database. These folders are stored within the mysql data directory.

    From there you can do a 'du -sh .*' to get the size of the table on disk.

    0 讨论(0)
  • 2020-11-30 16:55

    I would just use 'mysqldiskusage' tool as follow

    $ mysqldiskusage --server=user:password@localhost mydbname
    # Source on localhost: ... connected.
    
    # Database totals:
    +------------+----------------+
    | db_name    |         total  |
    +------------+----------------+
    | mydbaname  | 5,403,033,600  |
    +------------+----------------+
    
    Total database disk usage = 5,403,033,600 bytes or 5.03 GB
    
    0 讨论(0)
  • 2020-11-30 17:02

    Quick bit of SQL to get the top 20 biggest tables in MB.

    SELECT table_schema, table_name,
      ROUND((data_length+index_length)/POWER(1024,2),2) AS tablesize_mb
    FROM information_schema.tables
    ORDER BY tablesize_mb DESC LIMIT 20;
    

    Hope that's useful to somebody!

    0 讨论(0)
  • 2020-11-30 17:03

    Taken from How do I check how much disk space my database is using?

    You can check MySQL table size either by looking at phpMyAdmin in your control panel by clicking on the database name in the left frame and reading the size for the tables in there in the right frame.

    The below query will as well help to get the same information in bytes

    select SUM(data_length) + SUM(index_length) as total_size 
    from information_schema.tables 
    where table_schema = 'db_name' 
    and table_name='table_name';
    
    0 讨论(0)
  • 2020-11-30 17:05

    This won't be accurate for InnoDB tables. The size on disk is actually bigger than that reported via query.

    Please see this link from Percona for more information.

    https://www.percona.com/blog/2008/12/16/how-much-space-does-empty-innodb-table-take/

    0 讨论(0)
提交回复
热议问题