How do you fix a MySQL “Incorrect key file” error when you can't repair the table?

前端 未结 10 1892
眼角桃花
眼角桃花 2020-12-13 08:53

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

相关标签:
10条回答
  • 2020-12-13 09:24

    Simple "REPAIR the table" from PHPMYADMIN solved this problem for me.

    1. go to phpmyadmin
    2. open problematic table
    3. go to Operations tab (in my version of PMA)
    4. at the bottom you will find "Repair table" link
    0 讨论(0)
  • 2020-12-13 09:25

    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

    0 讨论(0)
  • 2020-12-13 09:34

    REPAIR TABLE tbl_name USE_FRM;

    Command only run when MySQL 'Storage Engine' type should be 'MyISAM'

    Hope this helps

    0 讨论(0)
  • 2020-12-13 09:39

    The storage engine (MyISAM) DOES support repair table. You should be able to repair it.

    If the repair fails then it's a sign that the table is very corrupted, you have no choice but to restore it from backups.

    If you have other systems (e.g. non-production with same software versions and schema) with an identical table then you might be able to fix it with some hackery (copying the frm an MYI files, followed by a repair).

    In essence, the trick is to avoid getting broken tables in the first place. This means always shutting your db down cleanly, never having it crash and never having hardware or power problems. In practice this isn't very likely, so if durability matters you may want to consider a more crash-safe storage engine.

    0 讨论(0)
  • 2020-12-13 09:39

    You'll need to run this command from the MySQL prompt:

    REPAIR TABLE tbl_name USE_FRM;
    

    From MySQL's documentation on the Repair command:

    The USE_FRM option is available for use if the .MYI index file is missing or if its header is corrupted. This option tells MySQL not to trust the information in the .MYI file header and to re-create it using information from the .frm file. This kind of repair cannot be done with myisamchk.

    0 讨论(0)
  • 2020-12-13 09:39

    this issue is because of low storage space availability of a particular drive(c:\ or d:\ etc.,), release some memory then it will work.

    Thanks Saikumar.P

    0 讨论(0)
提交回复
热议问题