I\'m trying to run a rather large query that is supposed to run nightly to populate a table. I\'m getting an error saying Incorrect key file for table \'/var/tmp/#sql
Simple "REPAIR the table" from PHPMYADMIN solved this problem for me.
Your query is generating a result set so large that it needs to build a temporary table either to hold some of the results or some intermediate product used in generating the result.
The temporary table is being generated in /var/tmp. This temporary table would appear to have been corrupted. Perhaps the device the temporary table was being built on ran out of space. However, usually this would normally result in an "out of space" error. Perhaps something else running on your machine has clobbered the temporary table.
Try reworking your query to use less space, or try reconfiguring your database so that a larger or safer partition is used for temporary tables.
MySQL Manual - B.5.4.4. Where MySQL Stores Temporary Files
REPAIR TABLE tbl_name USE_FRM;
Command only run when MySQL 'Storage Engine' type should be 'MyISAM'
Hope this helps
The storage engine (MyISAM) DOES support repair table. You should be able to repair it.
If the repair fails then it's a sign that the table is very corrupted, you have no choice but to restore it from backups.
If you have other systems (e.g. non-production with same software versions and schema) with an identical table then you might be able to fix it with some hackery (copying the frm an MYI files, followed by a repair).
In essence, the trick is to avoid getting broken tables in the first place. This means always shutting your db down cleanly, never having it crash and never having hardware or power problems. In practice this isn't very likely, so if durability matters you may want to consider a more crash-safe storage engine.
You'll need to run this command from the MySQL prompt:
REPAIR TABLE tbl_name USE_FRM;
From MySQL's documentation on the Repair command:
The USE_FRM option is available for use if the .MYI index file is missing or if its header is corrupted. This option tells MySQL not to trust the information in the .MYI file header and to re-create it using information from the .frm file. This kind of repair cannot be done with myisamchk.
this issue is because of low storage space availability of a particular drive(c:\ or d:\ etc.,), release some memory then it will work.
Thanks Saikumar.P