Results 1 to 3 of 3

Thread: MySQL - Size of Table

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    MySQL - Size of Table

    How can I get size of table in my MySQL DB ?

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Here's a function I wrote awhile ago to get all the tables from a database, plus their number of rows and size:

    Code:
    function gettableinfo($tdb) { '$tdb is the database
    
        $sql_result = "SHOW TABLE STATUS FROM " .$tdb;
        $result = mysql_query($sql_result);
    
        if($result) {
            $size = 0;
            $stuff = '<table cellpadding="2" cellspacing="0" style="border: 1px solid #000000; width: 250px;">
                <tr>
                    <td style="border-bottom: 1px solid #000000; padding-left: 4px; padding-right: 4px;"><b>Table Name</b></td>
                    <td style="border-bottom: 1px solid #000000; padding-left: 4px; padding-right: 4px;"><b>Records</b></td>
                    <td style="border-bottom: 1px solid #000000; padding-left: 4px; padding-right: 4px;"><b>Size</b></td>
                </tr>';
            while ($data = mysql_fetch_array($result)) {
                $size = $data["Data_length"] + $data["Index_length"];
    
                $stuff .= '<tr>
                    <td style="padding-left: 4px; padding-right: 4px;">' . $data['Name'] . '</td>
                    <td style="padding-left: 4px; padding-right: 4px;">' . $data['Rows'] . '</td>
                    <td align="right" style="padding-left: 4px; padding-right: 4px;">' . formatsize($size) . '</td>
                </tr>';
            }
            $stuff .= '</table>';
    
            return $stuff;
        }
    }
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width