Skip Navigation LinksHome > Categories > Code from a Category

How do you know the size of a MySQL database via php

User Name: serfcompany
Name: Serf
Contact Me:
Home Page:
php,mysql,javascript,html,css. Preferable working with Zend Framework. Good know javascript. I worked with various, javascript frameworks such as(jquery, YUI3, extjs, sencha touch). [More]
Viewed Times: 1215
Add Date: 05/12/2012
In this short article you will learn how to get the size of your database (DB) MySQL using the programming language PHP.

To begin with, we need a simple function formatfilesize (), which will convert the byte size in a more "readable form".

Next, we naturally want to connect to the database itself MySQL, to find out its size.

We define a variable that will contain the name of the database. Replace "databasename" in the name of your database:

Well, now we have the main thing - to calculate the size of our database. It is very simple - you just need to go through each database table and add up the size of the data index database:

Now our database size in bytes contained in the variable $ dbsise. It remains only to use the mentioned at the beginning of the function formatfilesize () to format this size (divide it into kilo-, mega-):

That's all. Good luck!

Post a Comment

Name: (Optional)
Email: (Optional, you can get an email if somebody replys your comments)*
Email me if somebody respons my comment below:
Enter Text
as Below:
(case insensitive, if hard to read, click the "get a new one" button)
* Your email address will not be shared with any third parties for any reason.
** Maximum 1000 charactors.