title: MySQL, Error 126: Incorrect key file for table
body: <p>I read the following question that has relevance, but the replies didn't satify me: <a href="https://stackoverflow.com/q/2011050/570796">MySQL: #126 - Incorrect key file for table</a></p>
  
  <hr>
  
  <h2>The problem</h2>
  
  <p>When running a query I get this error</p>
  
  <blockquote>
    <p>ERROR 126 (HY000): Incorrect key file for table` </p>
  </blockquote>
  
  <h2>The question</h2>
  
  <p>When I'm trying to find the problem I cant't find one, so I don't know how to fix it with the repair command.
  Is there any pointers to how I can find the problem causing this issue in any other way then I already have tried?</p>
  
  <hr>
  
  <h3>The query</h3>
  
  <pre><code>mysql&gt;       SELECT
      -&gt;         Process.processId,
      -&gt;         Domain.id AS domainId,
      -&gt;         Domain.host,
      -&gt;         Process.started,
      -&gt;         COUNT(DISTINCT Joppli.id) AS countedObjects,
      -&gt;         COUNT(DISTINCT Page.id)   AS countedPages,
      -&gt;         COUNT(DISTINCT Rule.id)   AS countedRules
      -&gt;       FROM Domain
      -&gt;         JOIN CustomScrapingRule
      -&gt;           AS Rule
      -&gt;           ON Rule.Domain_id = Domain.id
      -&gt;           LEFT JOIN StructuredData_Joppli
      -&gt;             AS Joppli
      -&gt;             ON Joppli.CustomScrapingRule_id = Rule.id
      -&gt;         LEFT JOIN Domain_Page
      -&gt;           AS Page
      -&gt;           ON Page.Domain_id = Domain.id
      -&gt;         LEFT JOIN Domain_Process
      -&gt;           AS Process
      -&gt;           ON Process.Domain_id = Domain.id
      -&gt;       WHERE Rule.CustomScrapingRule_id IS NULL
      -&gt;       GROUP BY Domain.id
      -&gt;       ORDER BY Domain.host;
  ERROR 126 (HY000): Incorrect key file for table '/tmp/#sql_2b5_4.MYI'; try to repair it
  </code></pre>
  
  <h3>mysqlcheck</h3>
  
  <pre><code>root@scraper:~# mysqlcheck -p scraper
  Enter password: 
  scraper.CustomScrapingRule                         OK
  scraper.Domain                                     OK
  scraper.Domain_Page                                OK
  scraper.Domain_Page_Rank                           OK
  scraper.Domain_Process                             OK
  scraper.Log                                        OK
  scraper.StructuredData_Joppli                      OK
  scraper.StructuredData_Joppli_Product              OK
  </code></pre>
  
  <h3>counted rows</h3>
  
  <pre><code>mysql&gt; select count(*) from CustomScrapingRule;
  +----------+
  | count(*) |
  +----------+
  |       26 |
  +----------+
  1 row in set (0.04 sec)
  
  mysql&gt; select count(*) from Domain;
  +----------+
  | count(*) |
  +----------+
  |        2 |
  +----------+
  1 row in set (0.01 sec)
  
  mysql&gt; select count(*) from Domain_Page;
  +----------+
  | count(*) |
  +----------+
  |   134288 |
  +----------+
  1 row in set (0.17 sec)
  
  mysql&gt; select count(*) from Domain_Page_Rank;
  +----------+
  | count(*) |
  +----------+
  |  4671111 |
  +----------+
  1 row in set (11.69 sec)
  
  mysql&gt; select count(*) from Domain_Process;
  +----------+
  | count(*) |
  +----------+
  |        2 |
  +----------+
  1 row in set (0.02 sec)
  
  mysql&gt; select count(*) from Log;
  +----------+
  | count(*) |
  +----------+
  |       41 |
  +----------+
  1 row in set (0.00 sec)
  
  mysql&gt; select count(*) from StructuredData_Joppli;
  +----------+
  | count(*) |
  +----------+
  |    11433 |
  +----------+
  1 row in set (0.16 sec)
  
  mysql&gt; select count(*) from StructuredData_Joppli_Product;
  +----------+
  | count(*) |
  +----------+
  |   130784 |
  +----------+
  1 row in set (0.20 sec)
  </code></pre>
  
  <hr>
  
  <h2>Update</h2>
  
  <hr>
  
  <h3>Disk usage</h3>
  
  <pre><code>root@scraper:/tmp# df -h
  Filesystem      Size  Used Avail Use% Mounted on
  /dev/xvda1       20G  4.7G   15G  26% /
  none            4.0K     0  4.0K   0% /sys/fs/cgroup
  udev            237M  4.0K  237M   1% /dev
  tmpfs            49M  188K   49M   1% /run
  none            5.0M     0  5.0M   0% /run/lock
  none            245M     0  245M   0% /run/shm
  none            100M     0  100M   0% /run/user
  </code></pre>