Solved

MySQL Physical Shrink?

Posted on 2011-02-24
5
1,077 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
ID: 34972557
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
ID: 34976082
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
ID: 34976957
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
ID: 34976958
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
ID: 34976959
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Merging spreadsheets 8 60
SQL Server - Getting the most recent engagement for each contact 9 36
SQL DATEADD 10 70
SQL Recursion schedule 13 14
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…

839 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