Solved

MySQL Physical Shrink?

Posted on 2011-02-24
5
1,073 Views
Last Modified: 2012-06-27
Our webhost company has told us we are over their 100MB limit in terms of the diskspace they will allocate to our MySQL db. i am a newbie with MySQL.

Is there a way you can try to physically shrink a MySQL database. Much like in Access and SQL Server. If so, can anybody point me in ther right direction in doing so. Thanks.

jason
0
Comment
Question by:jazzcatone
  • 3
5 Comments
 
LVL 4

Assisted Solution

by:MarioAlcaide
MarioAlcaide earned 166 total points
Comment Utility
One solution to shrinking a shared InnoDB tablespace is:
1. Backup *all* InnoDB tables with mysqldump.
2. Drop all of the InnoDB tables.
3. Physically delete the ibdata1 file at the filesystem interface.
4. Restart MySQL Server, which recreates a new, small tablespace file.
5. Restore all your InnoDB tables, which expands the tablespace file as needed.

Another solution is to use the option to store InnoDB tables in a separate file per table. See http://dev.mysql.com/doc/refman/5.0/en/multiple-tablespaces.html If you do that, you should be able to use OPTIMIZE TABLE or ALTER TABLE on each InnoDB table that you want to shrink. This is supposed to rebuild the .ibd file for the individual table.
0
 
LVL 10

Accepted Solution

by:
APNFSSC earned 167 total points
Comment Utility
If you use MYISAM table type then use the OPTIMIZE TABLE command mentioned above will rebuild the whole table and reduce the size
0
 
LVL 20

Expert Comment

by:Muhammad Wasif
Comment Utility
InnoDB solutions provided above will require that you have full control over the server, you know which databases using InnoDB tables otherwise deleting ibdata1 file may result in data loss of some InnoDB tables you are not aware of.

OPTIMIZE TABLE will only shrink table size if you had deleted some data from them. Beware using OPTIMIZE TABLE on InnoDB tables, it may reset the AUTO_INCREMENT counter due to a bug which is fixed in latest release.
0
 
LVL 20

Expert Comment

by:Muhammad Wasif
Comment Utility
InnoDB solutions provided above will require that you have full control over the server, you know which databases using InnoDB tables otherwise deleting ibdata1 file may result in data loss of some InnoDB tables you are not aware of.

OPTIMIZE TABLE will only shrink table size if you had deleted some data from them. Beware using OPTIMIZE TABLE on InnoDB tables, it may reset the AUTO_INCREMENT counter due to a bug which is fixed in latest release.
0
 
LVL 20

Assisted Solution

by:Muhammad Wasif
Muhammad Wasif earned 167 total points
Comment Utility
InnoDB solutions provided above will require that you have full control over the server, you know which databases using InnoDB tables otherwise deleting ibdata1 file may result in data loss of some InnoDB tables you are not aware of.

OPTIMIZE TABLE will only shrink table size if you had deleted some data from them. Beware using OPTIMIZE TABLE on InnoDB tables, it may reset the AUTO_INCREMENT counter due to a bug which is fixed in latest release.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article describes some very basic things about SQL Server filegroups.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now