Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MySQL Physical Shrink?

Posted on 2011-02-24
5
Medium Priority
?
1,090 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 664 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 668 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 668 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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
What we learned in Webroot's webinar on multi-vector protection.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

722 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