MySQL error: SQLSTATE[HY000]: General error: 126 Incorrect key file

If you ever get this kind of error:


SQLSTATE[HY000]: General error: 126 Incorrect key file for table '/tmp/#sql_3aef_0.MYI'; try to repair it

without an internet connection... you are in a bad place :-) The error message is very unclear about the issue. The problem is actually (most of the time) that the partition that holds the /tmp folder is too small to store a temporary table (for a big permanent table). This triggers an error at building the temporary table (or part of it) and shows you this error. To fix, edit you /etc/mysql/my.cnf file (or rather /etc/mysql/conf.d/local.cnf if you're clean) and locate (or add) the tmpdir directive. Change it from /tmp to /var/tmp, for example, and restart MySQL. Fixed! If you're using local.cnf, don't forget to add the [mysqld] line before the setting itself.