Where does mysql write temporary tables?
From the MySQL manual for 5.1:

..
On Windows, Netware and OS2, MySQL checks in order the values of the TMPDIR, TEMP, and TMP environment variables. For the first one found to be set, MySQL uses it and does not check those remaining. If none of TMPDIR, TEMP, or TMP are set, MySQL uses the Windows system default, which is usually C:\windows\temp.
..
ALTER TABLE creates a temporary copy of the original table in the same directory as the original table.

In newer MySQL versions it gets a bit more complicated to explain because there is also an in-place fast ALTER TABLE, but for 5.1 the answer to your question is simply &quot;in the table's directory&quot;.