Solved

MySQL Physical Shrink?

Posted on 2011-02-24
5
1,084 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

623 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