programing

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

css3 2023. 10. 7. 12:09

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

I wrote a query and this runs on my local server correctly it has less data,

but when i run this on production server it gets an error - (this has more data around 6GB)

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

Here is my query

SELECT   
    `j25_virtuemart_products`.`virtuemart_product_id`,
    `product_name`, 
    `product_unit`,
    `product_s_desc`,
    `file_url_thumb`,
    `virtuemart_custom_id`, 
    `custom_value`   
    FROM 
    `j25_virtuemart_product_customfields`,
    `j25_virtuemart_products`,
    `j25_virtuemart_products_en_gb`,
    `j25_virtuemart_product_medias`,
    `j25_virtuemart_medias`     
    WHERE
    (
    `j25_virtuemart_products`.`virtuemart_product_id`=`j25_virtuemart_products_en_gb`.`virtuemart_product_id`
    AND 
    `j25_virtuemart_products`.`virtuemart_product_id`=`j25_virtuemart_product_customfields`.`virtuemart_product_id`)

AND

    `j25_virtuemart_products`.`virtuemart_product_id`=`j25_virtuemart_product_medias`.`virtuemart_product_id`
    AND 
    `j25_virtuemart_product_medias`.`virtuemart_media_id`=`j25_virtuemart_medias`.`virtuemart_media_id`

    GROUP BY `j25_virtuemart_products`.`virtuemart_product_id`

    LIMIT 0, 1000;

Anyone know how to recover from that error - something like otimize this query or any other way thank you

The problem is caused by the lack of disk space in /tmp folder. The /tmp volume is used in queries that require to create temporary tables. These temporary tables are in MyISAM format even if the query is using only tables with InnoDB.

Here are some solutions:

  • 임시 테이블을 만들지 않도록 쿼리를 최적화합니다(쿼리를 rewrite하여 여러 쿼리로 분할하거나 적절한 인덱스를 추가하거나 pt-query-digest를 사용하여 실행 계획을 분석합니다.EXPLAIN <query>임시 테이블에 대한Percona 기사를 참조하십시오.
  • optimize MySQL so it will not create temporary tables (sort_buffer_size, join_buffer_size). See: https://dba.stackexchange.com/questions/53201/mysql-creates-temporary-tables-on-disk-how-do-i-stop-it
  • make tables smaller. If possible, delete unneeded rows
  • 사용하다SELECT table1.col1, table2,col1 ...대신에select *쿼리에 필요한 열만 사용하여 더 작은 임시 테이블을 생성하는 방법
  • use data types that take less space
  • add more disk space on the volume where /tmp folder resides
  • 임시 폴더 사용자를 mysql로 변경합니다. 를 설정하여TMPDIRmysqld 시작 전 환경 변수.포인트TMPDIR사용 가능한 공간이 더 많은 디스크 볼륨의 폴더로 이동합니다.사용할 수도 있습니다.tmpdir옵션 인/etc/my.cnf아니면--tmpdirmysqld 서비스의 명령 줄에 있습니다.참조: B.5.3.5 MySQL이 임시 파일을 저장하는 위치

Do these steps

Stop mysql service

rename the .myi file to x.old

Start mysql

REPAIR all the tables in query ,MySQL will rebuild key file

So many answers are above and the question owner already got the solution as suggested by @Hawili, and a long time has been passed since this problem was raised. But as this a common issue, I wanted to share my experience so that if someone got this issue again due to different reasons then can get solution from here.

사례 1:

가장 일반적인 이유는 쿼리가 /tmp 파티션 크기보다 큰 데이터를 가져오는 중이기 때문입니다.쿼리 중에 이 문제가 발생할 때마다 /tmp 폴더 크기를 확인합니다.임시 테이블이 자동으로 생성되고 제거되며, 이 쿼리 중에 사용 가능한 공간이 0으로 떨어지면 쿼리를 최적화해야 하거나 /tmp의 파티션 크기를 늘려야 합니다.

참고: 개별 쿼리가 아닌 경우가 있습니다. 많은 쿼리를 조합하여 동일한 서버에서 동시에 이 작업을 수행하면 일반적으로 개별 쿼리가 오류 없이 실행되는 이 문제가 발생할 수 있습니다.

사례 2:

복구해야 하는 myisam 테이블이 손상된 경우 디렉토리 경로가 오류 메시지의 /tmp와 다릅니다.

Case 3 : (희귀한 케이스)

테이블 조인이 잘못되어 이 오류가 발생할 수 있습니다.이것은 실제로 구문 오류이지만 mysql은 대신 이 오류를 던질 수 있습니다.자세한 내용은 아래 링크에서 확인하실 수 있습니다.

테이블 '/tmp/#sql_18b4_0'의 키 파일이 잘못되었습니다.수리를 시도해 보십시오.

하여 tmp dir 의합니다를 합니다.df -h할 수 충분한 공간이 몇 가 될 수도 임시 파일을 확장할 수 있는 충분한 공간이 있는지 확인하십시오. 몇 개의 기가바이트가 될 수도 있습니다.

편집: 여유 공간이 충분하다면 색인을 작성하고 있거나 WHERE 절에 포함되어 있는 모든 열이 색인화되었는지 확인하겠습니다.

데이터베이스 서버에 디스크 공간이 충분한지 확인합니다.디스크가 가득 차면 이 오류가 표시됩니다.이제 설정에 따라 어떤 폴더를 봐야 하는지가 달라집니다.

다음 명령을 사용했는데 오류가 사라졌습니다.

mysqlcheck --all-databases -r #repair

저는 이 솔루션을 cpanel 포럼에서 받았습니다.

나에게도 똑같은 문제가 있습니다.

실행.df -h 공간/tmp합니다가 합니다.

/tmp가 오버플로 파일 시스템인 경우:

overflow 1,0M 24K 1000K 3% /tmp

무슨 일이 일어났습니까?

에 가 좀 생겼습니다.//tmpRAM 메모리에서 임시로 사용합니다.것./tmp1MB 파티션은 시스템을 사용하기에 충분하지 않습니다.

해결책: 다음 명령을 실행하여 이 임시로 만든 파티션을 제거합니다를 제거합니다./tmp

sudo umount -l /tmp

이 하여 MySQL을 시작합니다./etc/init.d/mysqld restart막다른 골목에

언급URL : https://stackoverflow.com/questions/11805793/incorrect-key-file-for-table-tmp-sql-3c51-0-myi-try-to-repair-it