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

前端 未结 10 1893
眼角桃花
眼角桃花 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:42

    In my case, there was a disc space issue. I deleted some unwanted war files from my server and it worked after that.

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

    This happenes might be because you ran out of disk storage and the mysql files and starting files got corrupted

    The solution to be tried as below

    First we will move the tmp file to somewhere with larger space

    Step 1: Copy your existing /etc/my.cnf file to make a backup

    cp /etc/my.cnf{,.back-`date +%Y%m%d`}
    

    Step 2: Create your new directory, and set the correct permissions

    mkdir /home/mysqltmpdir
    chmod 1777 /home/mysqltmpdir
    

    Step 3: Open your /etc/my.cnf file

    nano /etc/my.cnf
    

    Step 4: Add below line under the [mysqld] section and save the file

    tmpdir=/home/mysqltmpdir
    

    Secondly you need to remove or error files and logs from the /var/lib/mysql/ib_* that means to remove anything that starts by "ib"

    rm /var/lib/mysql/ibdata1 and rm /var/lib/mysql/ibda.... and so on

    Thirdly you will need to make sure that there is a pid file available to have the database to write in

    Step 1 you need to edit /etc/my.cnf

    pid-file= /var/run/mysqld/mysqld.pid 
    

    Step 2 create the directory with the file to point to

     mkdir /var/run/mysqld
     touch /var/run/mysqld/mysqld.pid
     chown -R mysql:mysql /var/run/mysqld
    

    Last step restart mysql server

    /etc/init.d/mysql restart
    
    0 讨论(0)
  • 2020-12-13 09:43

    Apply proper charset and collation to database, table and columns/fields.

    I creates database and table structure using sql queries from one server to another. it creates database structure as follows:

    1. database with charset of "utf8", collation of "utf8_general_ci"
    2. tables with charset of "utf8" and collation of "utf8_bin".
    3. table columns / fields have charset "utf8" and collation of "utf8_bin".

    I change collation of table and column to utf8_general_ci, and it resolves the error.

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

    You must change the location of MySQL's temporary folder which is '/tmp' in most cases to a location with a bigger disk space. Change it in MySQL's config file.

    Basically your server is running out of disk space where /tmp is located.

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