MySQL Database Size?

I know how much disk space I can have for the html pages, but I can’t find any indication for the size of MySQL database.

In fact, where can I find the size of the MySQL database??

Help!

The MySQL database size is included in the 1,5Gb.
To find out how much space your database is using, goto PhpMyAdmin and look at the bottom of the tables and it should say the size.

Thanks

I have searched through PhpMyAdmin and although it states how many records, there is no mention of size kb’s.

Am I looking in the wrong place?

Probably not, I was thinking of an older versjon of PhpMyAdmin, just checked the 000webhost one and at least I didn’t findt it.

That´s correct. For some reason phpMyAdmin doesn´t display the database size. But there´s a simple script you can use to determine the size. Just save the following code as whatevername.php, upload it to your site and open the file in your browser

<html><head><title>mysql database size</title></head><body> 
<h1>mysql database size</h1> 
<?php  
function file_size_info($filesize) { 
 $bytes = array('KB', 'KB', 'MB', 'GB', 'TB'); # values are always displayed  
 if ($filesize < 1024) $filesize = 1; # in at least kilobytes. 
 for ($i = 0; $filesize > 1024; $i++) $filesize /= 1024; 
 $file_size_info['size'] = ceil($filesize); 
 $file_size_info['type'] = $bytes[$i]; 
 return $file_size_info; 
} 
$db_server = 'put your server here'; 
$db_user = 'put your mysql user here'; 
$db_pwd = 'put your password here'; 
$db_name = 'put your db name here'; 
$db_link = @mysql_connect($db_server, $db_user, $db_pwd) 
 or exit('Could not connect: ' . mysql_error()); 
$db = @mysql_select_db($db_name, $db_link) 
 or exit('Could not select database: ' . mysql_error()); 
// Calculate DB size by adding table size + index size: 
$rows = mysql_query("SHOW TABLE STATUS"); 
$dbsize = 0; 
while ($row = mysql_fetch_array($rows)) { 
 $dbsize += $row['Data_length'] + $row['Index_length']; 
} 
print "database size is: $dbsize bytes<br />"; 
print 'or<br />'; 
$dbsize = file_size_info($dbsize); 
print "database size is: {$dbsize['size']} {$dbsize['type']}"; 
?> 
</body></html> 

Change this part to reflect your details

$db_server = 'put your server here'; 
$db_user = 'put your mysql user here'; 
$db_pwd = 'put your password here'; 
$db_name = 'put your db name here'; 

Working demo of the script on my test site at http://just2test.freeiz.com/mysql.php

Very interesting your script. Thanks for posting it

@ Bad Karma[CORE],

Thanks for sharing that script, would you mind if I showed it on my blog?

Don´t need to ask for that, just copy and paste away :slight_smile:
Though keep in mind that the result might be a bit of as the .frm files are not taken into account (usually approx 9kb each). Another thing you might consider changing in the script is the while loop.

Replace the while loop with this

while ($row = mysql_fetch_array($rows)) { 
 $dbsize += $row['Data_length'] + $row['Index_length']; 
 print '<pre>Table: <strong>' . $row['Name'] . '</strong><br />'; 
 print 'database size. . .: ' . $row['Data_length'] . '<br />'; 
 print 'Index size . . . .: ' . $row['Index_length'] . '<br />'; 
 print 'Total size . . . .: ' . ($row['Data_length'] + $row['Index_length']) . '<br /></pre>'; 
} 

and it will give you a report of how big each table is. I just changed the code on my test site -> http://just2test.freeiz.com/mysql.php which now displays the detailed information.

Thank you :slight_smile:

Absolutely perfect - very handy little script. Thank you.

Now all I need is a server that works and I’m away! :slight_smile: