Mysql Safe to delete .TMD file? - mysql

Long story short. I had a very large corrupt InnoDB table. Tried a number of things to rebuild/recover the table. (I was finally successful) However, one of the things I tried was building a new table with Myisam engine with force innodb reovery on, however there was another crash along the way and I'm left with a .TMD file for that table.
Just curious if I'm safe to delete this file? Table does not show up anywhere in the database, via show tables, drop table doesn't do anything. etc. At this point its just taking up disk space in my data directory.

The .TMD file is an intermediate data file for a table that needs to recreate its data file.
So you can remove it because it's normally used as a temporarly file but you could rename the file and check what happens just in case.

Related

Delete from InnoDB table without having a binary log

I have an InnoDB table used to pre-process some data before rendering a web page. It is a very bulky table. And; I do not need to keep some old records it it.
To keep the database size slim, I need to delete the data. But partially only.
TRUNCATE does not work, but DELETE.
Will the database create a bigger log files with this?
Is there a way to delete the data without producing a binary log?
You can use mysql option named --binlog-ignore-db so that particular db is not logged in binary log. so create your bulky table in binlog ignored db.
Also, you can use CREATE TEMPORARY TABLE so that temp table will be deleted after session closed.

Very large MySQL database, deleted a column, and the size of the database increased by 50%

I have a 20gb MySQL database which contains about 30 million rows of data in one table. I wanted to delete a column within that table to clear up some space.
I dropped the column via phpMyAdmin which took about 15 minutes and checked the disk usage in my server. It went from 20gb to 28gb used after deleting a column that was filled with data.
Did I do something wrong? Am I missing something obvious?
I did nothing else while I was trying to delete the column.
Update: Actually, when I go to the database summary page that lists the tables in phpMyAdmin, it also lists their size. The size of the tables only adds up to 10gb.
When I check the size being used on my server via df -h it says /dev/vda is using 28gb.
The only other files on the server are a few small PHP files. What is taking up this 18gb gap?
Most likely explanation is that you are not using file-per-table mode, and the ibdata1 file that contains all tables and indexes increased during the ALTER TABLE. When you delete a column, MySQL has to create a new copy of the table, move all the data into it (minus the column you deleted) and then drop the original table. Near the end of this process, two copies of the table (minus the column you deleted in one copy) need to be stored simultaneously. Then when that's complete, it drops the original copy and that space can be reused in the future.
Unfortunately, there's no way to shrink the ibdata1. It remains at a size equal to its high-water mark. To recover the disk space, you have to:
Dump all InnoDB tables (or convert them to MyISAM temporarily)
Shut down MySQL Server
Remove ibdata1 and ib_logfile*
Set innodb_file_per_table=1 in your my.cnf
Restart. The missing ibdata1 will be created at the initial default size.
Import your data.
Now the tables will occupy a separate file per table. When you ALTER or OPTIMIZE them, they will recover space. This mode is enabled by default in MySQL 5.6.

MySQL ALTER TABLE on tables too large to duplicate

When adding a column to a MyISAM table, MySQL will Create>Copy>Drop>Rename. I have a table which is sufficiently large that it cannot be duplicated in the server's remaining free space. Attempting to add a column then results in the disk filling. Time is not an issue here, neither is table availability, just disk space.
Short of copying the data to another server, truncating, altering, and copying back, is there a way to add a column to a MyISAM table without it creating a temporary table and duplicating all the data?
You could create a new, empty table, manually move the data over in chunks (INSERT into new, DELETE from old a certain number of rows), drop the old table and rename the new table. Essentially what MySQL does, but moving the data over instead of copying it, which should allow you to use less space.
In general I try to keep enough free space to be able to rebuild my largest table. This allows me to run OPTIMIZE TABLE or ALTER TABLE when necessary.
Do you have another disk mounted on your server?
When space is too tight to rebuild a given table, my preferred workaround is to temporarily move some other table(s) to a separate disk volume. I do this by stopping MySQL, moving the relevant data files (MYD and MYI, or ibd), and then creating a symlink at the original location that points at the new location, and starting MySQL. Once the table rebuild is done I reverse that process to move the other table(s) back to their original location.

Splitting an existing innodb table into separate files

I'm wondering if its possible to split an existing InnoDB table into multiple files. I understand that if you specify the innodb_file_per_table prior to creating the tables; they are split into separate files. But I have an existing database that is 150GB; and I now need to move a table to another machine.
Normally it wouldn't be a problem. But I noticed that when you use InnoDB and try to truncate/drop a table; the space isn't reallocated on the disk (ie, the ibdata1 doesn't reduce in size bug report). This is a problem as the reason I'm moving the table is due to space issues on my current server. Hence why I'm trying to split this existing ibdata1 file into separate files for tables. This will then give me the flexibility to reallocate the space on disk once I have moved the table.

MySQL data file won't shrink

My ibdata1 file for MySQL database grew to about 32GB over time. Recently I deleted about 10GB of data from my databases (and restarted mysql for good measure), but the file won't shrink. Is there any way to reduce the size of this file
The file size of InnoDB tablespaces will never reduce automatically, no matter how much data you delete.
What you could do, although it is a lot of effort, is to create one tablespace for every table by setting
innodb_file_per_table
The long part about this is, that you need to export ALL DATA from the mysql server (setting up a new server would be easier) and then reimport the data. Instead of one single ibdata1 file which holds the data for each and every table, you will find a lot of files called tablename.ibd which hold the data only for one single table.
Afterwards:
When you then delete a lot of data from tables, you can let mysql recreate the data-file by issuing
alter table <tablename> engine=myisam;
to switch to MyIsam (and have the InnoDB data file for this table deleted) and then
alter table <tablename> engine=innodb;
to recreate the table.
Unless you set innodb_file_per_table, ibdata1 holds all InnoDB tables plus undo.
This file never shrinks.
To shrink it, you should (at your own risk):
Backup and drop all InnoDB tables in all databases
Delete the file manually
Reinitialize InnoDB storage (by restarting mysqld) and
Restore the tables from backup.
If you set innodb_file_per_table, you'll still have to do this to reclaim the space, but in this case you'll be able to do this on per-table basis, without affecting the other tables.
Note that the undo is still held in ibdata, even with innodb_file_per_table set.
Adding, Removing, or Resizing InnoDB Data and Log Files
Run optimize table your_db.your_table; sql request
or use mysql workbench migration wizard and it will create database copy with reduced size