156

I was repairing this table suddenly server hanged and when I returned back all tables are ok but this one showing 'in use' and when I try to repair it doesn't proceed.

ERROR 144 - Table './extas_d47727/xzclf_ads' is marked as crashed and last (automatic?) repair failed

What can I do to repair it?

2
  • 1
    I've seen this mostly happen when the underlying file system goes out of free inodes. Check with df -hi. Usually something is filling it with loads of small files, like e.g. php session files that don't get cleaned up.
    – Zrin
    Oct 21, 2014 at 10:24
  • 1
    This discussion is probably aimed at MyISAM tables only.
    – Rick James
    Apr 13, 2021 at 16:01

12 Answers 12

311

If your MySQL process is running, stop it. On Debian:

sudo service mysql stop

Go to your data folder. On Debian:

cd /var/lib/mysql/$DATABASE_NAME

Try running:

myisamchk -r $TABLE_NAME

If that doesn't work, you can try:

myisamchk -r -v -f $TABLE_NAME

You can start your MySQL server again. On Debian:

sudo service mysql start
5
  • 8
    I've got a myisam_sort_buffer_size is too small error, so this command worked for me: myisamchk -r -v --sort_buffer_size=2G <table_name>
    – dusan
    May 22, 2013 at 19:33
  • My disk filled up while doing this, so it failed. After clearing space and trying it again, I was told it couldn't create "table_file_name.TMD". I guessed that it was because it already existed from when it failed before. After removing that file, it worked. Sep 18, 2013 at 13:07
  • This solved my problem as well thank you. Using the --force option is what allows the repair to run even if something with the stucture or information is incorrect.
    – contrid
    Aug 16, 2017 at 13:27
  • I ran into the error myisamchk: error: Not enough memory for blob at 541031156 (need 1953787962). The command myisamchk --max-record-length=1048576 -r -v -f $TABLE_NAME helped. I also created a backup copy of the file first; maybe a good general precaution. Jun 3, 2019 at 21:34
  • I'm getting similar type but not for single table, mysql crashed after few seconds of started. Would anybody can help to solve this issue. I've followed some solutions but unfortunately replaced by backup folder. Jan 24 at 6:48
134

Try running the following query:

repair table <table_name>;

I had the same issue and it solved me the problem.

1
  • 1
    This was a quick fix! Had a "bad" options table. Make sure that you select the correct database first !
    – jyllstuart
    Jan 10, 2019 at 15:54
48
+50

This was my experience resolving this issue. I'm using XAMPP. I was getting the error below

 Fatal error: Can't open and lock privilege tables: Table '.\mysql\db' is marked as crashed and last (automatic?) repair failed  

This is what I did to resolve it, step by step:

  1. went to location C:\xampp\mysql, For you, location may be different, make sure you are in right file location.
  2. created backup of the data folder as data-old.
  3. copied folder "mysql" from C:\xampp\mysql\backup
  4. pasted it inside C:\xampp\mysql\data\ replacing the old mysql folder.

And it worked. Keep in mind, I have already tried around 10 solutions and they didnt work for me. This solutions may or may not work for you but regardless, make backup of your data folder before you do anything.

Note: I would always opt to resolve this with repair command but in my case, i wasnt able to get mysql started at all and i wasnt able to get myisamchk command to work.

Regardless of what you do, create a periodic backup of your database.

5
  • 4
    One small comment, taking this solution that worked for me too may require you yo redefine MySQL password. From XAMPP UI open "shell" and use the command # mysqladmin -u root password Type the password you previously used and confirm password. Not it works again. Jun 5, 2021 at 10:44
  • 1
    top answer, worked out smooth without any errors
    – Sparkm4n
    Jan 7, 2022 at 22:05
  • 1
    none of the solutions worked for me. only this solution worked. its weird cause other people said the same thing... Aug 16, 2022 at 4:59
  • This si the only solution worked for me. Dec 9, 2022 at 9:27
  • Yeap that's the one Key is to always check mysql log file last few lines for error and you'll get answer within one minute :D Dec 14, 2022 at 5:19
16

If it gives you permission denial while moving to /var/lib/mysql then use the following solution

$ cd /var/lib/
$ sudo -u mysql myisamchk -r -v -f mysql/<DB_NAME>/<TABLE_NAME>
1
  • Perfect, I was getting the permissions error. This sorted it. Jun 14, 2022 at 10:25
9

I needed to add USE_FRM to the repair statement to make it work.

REPAIR TABLE <table_name> USE_FRM;
4

I got myisamchk: error: myisam_sort_buffer_size is too small as error.

The solution

myisamchk -r -v mysql/<DB_NAME>/<TABLE_NAME> --sort_buffer_size=2G
3

Go to data_dir and remove the Your_table.TMP file after repairing <Your_table> table.

1
  • 1
    search for it with this command grep -r datadir /etc/mysql/. Should be /var/lib/mysql under debian and ubuntu.
    – ThorstenS
    Feb 10, 2016 at 6:30
3

If this happend to your XAMPP installation, just copy global_priv.MAD and global_priv.MAI files from ./xampp/mysql/backup/mysql/ to ./xampp/mysql/data/mysql/.

1
  • 1
    's solution worked for me, only in my case the table was ./mysql/db. I tried running myisamchk, but if pass 'db' as table name, it says 'file not found', if a specify the extension, i get "...is not a db file"
    – Marlon
    Jan 26, 2021 at 15:29
2

Without stopping the database I go to this folder

cd /var/lib/mysql/$DATABASE_NAME

and then execute the following command

myisamchk -r -v -f $TABLE_NAME

enter image description here

Without having any issue the command successfully completed and resolve the issue

Thank you

3
1

This is a 100% solution. I tried it myself.

myisamchk -r -v -f --sort_buffer_size=128M --key_buffer_size=128M /var/lib/mysql/databasename/tabloname

0
0

I tried the options in the existing answers, mainly the one marked correct which did not work in my scenario. However, what did work was using phpMyAdmin. Select the database and then select the table, from the bottom drop down menu select "Repair table".

  • Server type: MySQL
  • Server version: 5.7.23 - MySQL Community Server (GPL)
  • phpMyAdmin: Version information: 4.7.7
0

enter to your mysql and select your database then

repair table ;

this work with me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.