PDA

View Full Version : Retrieving filesize of MySQL database and tables


u9x
10-15-05, 07:29 PM
Is there a way, preferrably quick and clean, to retrieve the filesize of my database and each of its tables? I would like to display that info within my custom CMS but haven't been able to find anything in the MySQL manual. The only method that comes to mind is to get the size of these files through PHP's filesize() function or LS-ing through a system() or exec() call. However, I don't know where these database files are located for my account (site is on magnatar, database is mysql03) and if checking this way would be problematic due to the server clustering.

RTH10260
10-15-05, 08:30 PM
Is there a way, preferrably quick and clean, to retrieve the filesize of my database and each of its tables? I would like to display that info within my custom CMS but haven't been able to find anything in the MySQL manual. The only method that comes to mind is to get the size of these files through PHP's filesize() function or LS-ing through a system() or exec() call. However, I don't know where these database files are located for my account (site is on magnatar, database is mysql03) and if checking this way would be problematic due to the server clustering.
First, you don't have an access to the file storage on the database servers.

But just use the regular MySql management statements. You want to run a query using "SHOW TABLE STATUS [FROM db_name] [LIKE 'pattern']". Put this into a regular query like you would run a SELECT statement.
ref: http://dev.mysql.com/doc/refman/4.1/en/show-table-status.html

This is the data you see in phpmyadmin on the database structure page, listed in the stats column at right, or in the stats block displayed for a table structure.

Note: it's probably not a good idea to show these stats on every page. The overhead could be noticable. Reserve this information to some admin webpage.

u9x
10-15-05, 08:37 PM
Thanks, Richard:D I will look into that. fwiw, this info would only be on a database analysis report page, not on multiple pages, but thanks for pointing out the overhead issue.

:D

EDIT: Yep, that's exactly what I'm looking for (and then some)! Thx again :)