Category Archives: MySQL

MySQL error "Incorrect key file for table"

Usually this error can be corrected by running "myisamchk -r <tablename.MYI>" on the myisam table in question. But this time it didn't resolve the error.

Let's take a close look at the error message:

Incorrect key file for table '/tmp/#sql_5b1f_0.MYI'; try to repair it [126]

The location of the myisam file is really strange. It is in the /tmp folder and not in the database directory. Also the name of the table looks like it is not part of the original database.

If this happens mysql is trying to create a temporary table in the tmp folder to resolve a very large query. It is using temporary tables to store intermediate results for large queries. But if there is not enough space in the tmp folder to create the corresponding key files, MySQL throws the above error message. Which is - in this case - a little bit misleading.

To resolve the problem I just had to enlarge my /tmp partition. Originally it was just 350 MB in size, which is really a bad idea for a database server. So I gave it another 800 MB, and the error message disappeared.