MySQL incorrect key file for tmp table when making multiple joins

后端 未结 11 1173
轻奢々
轻奢々 2020-11-27 17:01

I don\'t come here for help often but I am pretty frustrated by this and I am hoping someone has encountered it before.

Whenever I try to fetch records from a table

相关标签:
11条回答
  • 2020-11-27 17:30

    I had this problem with a query on a table that had 500K+ records. It was giving me the same exact type of error, pointing to a .MYI file in the /tmp directory that was rarely there upon checking. I had already increased the heap and temp file sizes in the /etc/my.cnf file.

    The problem with the query was the it did indeed contain a ORDER clause at the end, omitting it made the query work without error. It also had a LIMIT. I was trying to look at the most recent 5 records in the table. With the ORDER clause included it choked and gave the error.

    What was happening was the mysqld was creating an internal temp table with ALL the records from the giant table to apply the ORDER.

    The way that I got around this is to apply an additional WHERE condition, limiting the records from the giant table to some smaller set. I conveniently had a datetime field to do the filtering from.

    I hope that helps someone.

    0 讨论(0)
  • 2020-11-27 17:33

    Using the EXPLAIN keyword may help find out how to best optimize this query. Essentially, what you need to do is get the result set as small as possible as quickly as possible. If you have a result set of every row in core_username until the end, when you order it you run the risk of... this.

    If you can do the ordering on core_username alone without a problem, you may want to get the min() row as a subquery.

    0 讨论(0)
  • 2020-11-27 17:36

    the index keys for one of the 3 tables might be bad, try running a repair command on all 3 tables.

    0 讨论(0)
  • 2020-11-27 17:42

    Sometimes when this error happens with temp tables:

    #126 - Incorrect key file for table '/tmp/#sql_64d_0.MYI'; try to repair it
    

    It can be because the /tmp folder is running out of space. On some Linux installations, /tmp is in its own partition and does not have much space - big MySQL queries will fill it up.

    You can use df -h to check whether \tmp is in its own partition, and how much space is allocated to it.

    If it is in its own partition and short of space, you can either:

    (a) modify /tmp so that its parition has more space (either by reallocating or moving it to the main partition - e.g. see here)
    (b) changing MySql config so that it uses a different temp folder on a different partition, e.g. /var/tmp

    0 讨论(0)
  • 2020-11-27 17:42

    Only increase the file tmp, because mysql doesn't have space in it, for queries...

    mount -o remount,size=[NEW MAX SIZE HERE] tmpfs /tmp
    

    Links reference:

    General error: 126 Incorrect key file for table ‘/tmp/#sql_254c_0.MYI’; try to repair it

    [ERROR] /usr/sbin/mysqld: Incorrect key file for table '/mysqltmp/#sql_ca1a_0.MYI'; try to repair it

    How to increase /tmp partition size

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