We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,453 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

MySQL database size limit crossed

Hi,

I have a database called my_db1 which contains 3 tables. Out of the 3 tables one table is being populated 24*7. My hosting provider (i.e godaddy) provides 25 Mysql databases 1 GB each.
What should I do if the database exceeds the 1 GB size limit? Is there a way that my PHP script can detect the size of the database and automatically starts populating data to a different database with the same table structure?

Thanks
Anita

3
Contributors
4
Replies
2 Weeks
Discussion Span
1 Year Ago
Last Updated
5
Views
Question
Answered
anita.kcx
Newbie Poster
11 posts since Mar 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Unfortunately, GoDaddy doesn't allow you to increase your database size limit.

However you can have more than one database, if you upgrade you account plan.

If you have the Economy plan, you can have 10 databases, Deluxe gives you 25 database and you can also have an Unlimited plan.

The PHP sqcript to get your database size is as follows:

<?php
$db = mysql_connect("hostname", "username","password"); // MySql database connection
mysql_select_db("dbname",$db); //Select the database
?>

<?php
{
$sql = "SHOW TABLE STATUS"; //Command to get the database status
$result = mysql_query($sql); 
while($row = mysql_fetch_array($result))
{
$dbsize = $row['Data_length']+$row['Index_length']; // Columns 'Index_length' and 'Data_length' of each row calculated
}
echo($dbsize); // Print the database size
}
?>

Once you have the size (with $dbsize) you can check that thedbsize < 1GB and if true, run the following PHP script to create a table and it's tables:

<?php
$con = mysql_connect("hostname", "username","password"); 
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

// Create database
if (mysql_query("CREATE DATABASE my_db",$con))
  {
  echo "Database created";
  }
else
  {
  echo "Error creating database: " . mysql_error();
  }

// Create table
mysql_select_db("my_db", $con);
$sql = "CREATE TABLE Employees
(
FirstName varchar(15),
LastName varchar(15),
Age int
)";

// Execute query
mysql_query($sql,$con);

mysql_close($con);
?>

Hope that helps :)

StephNicolaou
Posting Whiz in Training
204 posts since Nov 2007
Reputation Points: 77
Solved Threads: 18
Skill Endorsements: 0

Hey Thanks, this is what I was looking for.

Thanks,
Anita

anita.kcx
Newbie Poster
11 posts since Mar 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

No problem. Could you please mark this thread as solved if done so?

Thanks :)

StephNicolaou
Posting Whiz in Training
204 posts since Nov 2007
Reputation Points: 77
Solved Threads: 18
Skill Endorsements: 0
Question Answered as of 1 Year Ago by StephNicolaou

You can also retrieve the information from the INFORMATION_SCHEMA.TABLES table.

effectiveMySQL
Newbie Poster
2 posts since Mar 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0698 seconds using 2.68MB