patternsqlMinor
Moving an ibd file temporarily to free up disk space
Viewed 0 times
filespacediskfreeibdmovingtemporarily
Problem
I want to optimize an InnoDB table but I do not have enough disk space. I have enabled
Is it okay to move
MySQL server version 5.1.73
innodb_file_per_table, so each table has *.ibd for each of their partitions. For example:512MB /var/lib/mysql/ib_logfile0
512MB /var/lib/mysql/ib_logfile1
70GB /var/lib/mysql/ibdata1
100GB /var/lib/mysql/dbname/table_a.ibd (*)
100GB /var/lib/mysql/dbname/table_b.ibd (*)
12KB /var/lib/mysql/dbname/table_a.frm
12KB /var/lib/mysql/dbname/table_b.frm
4KB /var/lib/mysql/dbname/table_a.TRG
4KB /var/lib/mysql/dbname/table_b.TRGIs it okay to move
table_a.ibd to another disk, optmize table_b, and move table_a.ibd back to its original place? I don't want to lose any data, or break anything.MySQL server version 5.1.73
Solution
It would make more sense to me to take a backup, remove the table instead of moving it, perform your optimize and then restore the table you dropped. This would avoid moving tables around unnecessarily and leaving your database in an incoherent state. You would also want to prevent incoming connections from the outside by putting bind-address = 127.0.0.1 in my.cnf and then restarting mysql.
Backup your whole database first with mysqldump
--single-transaction is the safest way to backup innodb
--routines backsup stored procedures.
gzip just compresses the backup nicely, you can open it backup with zcat.
1: Backup the table in question
2: Make sure the backup you created of the table has your data with zcat
Drop the table
3: Perform your maintenance with optimize
4: Restore the table
Backup your whole database first with mysqldump
mysqldump
--single-transaction \
--routines \
-u root -p nameofdatabase | gzip -9 > nameofdatabase.gz--single-transaction is the safest way to backup innodb
--routines backsup stored procedures.
gzip just compresses the backup nicely, you can open it backup with zcat.
1: Backup the table in question
mysqldump
--single-transaction \
-u root -p nameofdatabase nameoftable | gzip -9 > nameoftable.gz2: Make sure the backup you created of the table has your data with zcat
zcat nameoftable.gz | lessDrop the table
mysql> drop table nameoftable;3: Perform your maintenance with optimize
4: Restore the table
zcat nameoftable.gz | mysql -u root -p nameofdatabaseCode Snippets
mysqldump
--single-transaction \
--routines \
-u root -p nameofdatabase | gzip -9 > nameofdatabase.gzmysqldump
--single-transaction \
-u root -p nameofdatabase nameoftable | gzip -9 > nameoftable.gzzcat nameoftable.gz | lessmysql> drop table nameoftable;zcat nameoftable.gz | mysql -u root -p nameofdatabaseContext
StackExchange Database Administrators Q#118140, answer score: 3
Revisions (0)
No revisions yet.