154

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • 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 '14 at 10:24
  • This discussion is probably aimed at MyISAM tables only. – Rick James Apr 13 '21 at 16:01

12 Answers12

309

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
cubuspl42
  • 7,833
  • 4
  • 41
  • 65
Aleksandar Vucetic
  • 14,715
  • 9
  • 53
  • 56
  • 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 ` – dusan May 22 '13 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. – Tyler Collier Sep 18 '13 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 '17 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. – Dawn Drescher Jun 03 '19 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. – Kamran Allana Jan 24 '23 at 06:48
134

Try running the following query:

repair table <table_name>;

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

cREcker
  • 2,323
  • 1
  • 16
  • 13
45

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.

ashish
  • 3,555
  • 1
  • 20
  • 26
  • 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. – Gilad Tiram Jun 05 '21 at 10:44
  • 1
    top answer, worked out smooth without any errors – Sparkm4n Jan 07 '22 at 22:05
  • 1
    none of the solutions worked for me. only this solution worked. its weird cause other people said the same thing... – Daniel_Ranjbar Aug 16 '22 at 04:59
  • This si the only solution worked for me. – Nijat Mursali Dec 09 '22 at 09: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 – Vipertecpro Dec 14 '22 at 05: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>
crazycrv
  • 2,395
  • 2
  • 19
  • 20
9

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

REPAIR TABLE <table_name> USE_FRM;
Mark
  • 371
  • 3
  • 5
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
ThorstenS
  • 317
  • 1
  • 7
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/.

Qrzysio
  • 1,147
  • 3
  • 12
  • 25
  • 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 '21 at 15:29
2

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

TLama
  • 75,147
  • 17
  • 214
  • 392
  • 1
    search for it with this command `grep -r datadir /etc/mysql/`. Should be `/var/lib/mysql` under debian and ubuntu. – ThorstenS Feb 10 '16 at 06:30
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

  • Please don't add "thank you" as an answer. Instead, vote up the answers that you find helpful. - [From Review](/review/late-answers/30197684) – D.Zotov Oct 28 '21 at 08:30
  • This really works for the crash table situation, the only note I would like to add - replace `$TABLE_NAME` by your table file name (without extension). – Nah Aug 01 '22 at 11:56
  • Please [don’t post images of code, error messages, or other textual data.](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-on-so-when-asking-a-question/285557#285557) – tripleee Mar 26 '23 at 10:32
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

cryptox1
  • 19
  • 1
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
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
0

enter to your mysql and select your database then

repair table ;

this work with me

Aziz Adel
  • 1
  • 1