ibdata1 shrink

Good day

we have production MySql database
ibdata1 is getting larger every day
What is the best way to shrink it?
Database is a production one, so downtime may be a problem


Thank you
mattyinteractiveAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kerem ERSOYPresidentCommented:
Hi,

There's no way to shrink it except for exporting the database deleting and recreating the tables.
- Stop the MySql Daemon.
- Create a dump with this command:
 mysqldump -u root -p --all-databases > alldatabases.sql
- Drop all tabases excluding mysql:
$ mysql -u root -p
mysql> show databases;
mysql> drop database XXXX;
- Start MySQL
- Restore the dbs:
mysql -u root -p < alldatabases.sql

Another method is to make MySQL to save every database into its own file instead of one big file (ibdata1). Then restore the data. The Stpes are:

- Stop the MySql Daemon.
- Create a dump with this command:
 mysqldump -u root -p --all-databases > alldatabases.sql
- Logon to database and drop each database excluding mysql.
$ mysql -u root -p
mysql> show databases;
mysql> drop database XXXX;
- Edit /etc/my.cnf and add this command unde [mysql] tab:
[mysqld]
.
.
.
innodb_file_per_table
- Remove ibdata1, ib_logfile0, ib_logfile1
- Start MySQL
- Restore the dbs:
mysql -u root -p < alldatabases.sql


The second method will make it easier to backup and restore operations.. It will only need the specific db to be down and restored again...

Cheer,
K.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mattyinteractiveAuthor Commented:
Kerem,

Thank you for advise!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.