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
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