You are here

PDOException: SQLSTATE[HY000]: General error: 144 Table 'cache_menu' is marked as crashed and last (automatic?) repair failed: DELETE FROM {cache_menu};

Submitted by Druss on Tue, 2013-04-23 10:38

While trying to edit a menu on a Drupal site, I found that none of my changes were being saved. Looking at the logs led me to the following error message:

PDOException: SQLSTATE[HY000]: General error: 144 Table 'cache_menu' is marked as crashed and last (automatic?) repair failed: DELETE FROM {cache_menu};

Simply restarting MySQL did not fix things and it looked like I had to get my hands a li'l dirty.

After much faffing about on Google, it appeared that I needed to run a myisamchk on the cache_menu table in question. This is on an Ubuntu server when logged in as "root".

  1. Navigate to the MySQL data directory for the database in question. In my case, this was in /var/lib/mysql/foobar.
  2. In there, run a myisamchk on the table in question like so:
    root:/var/lib/mysql/foobar# myisamchk -c cache_menu.MYI
    Checking MyISAM file: cache_menu.MYI
    Data records:       0   Deleted blocks:       0
    myisamchk: warning: Table is marked as crashed and last repair failed
    - check file-size
    myisamchk: warning: Size of indexfile is: 1892352       Should be: 4096
    - check record delete-chain
    - check key delete-chain
    - check index reference
    - check data record references index: 1
    - check data record references index: 2
    - check record links
    myisamchk: error: Record-count is not ok; is 32641        Should be: 0
    myisamchk: warning: Found      32641 key parts. Should be: 0
    MyISAM-table 'cache_menu.MYI' is corrupted
    Fix it using switch "-r" or "-o"
  3. As myisamchk suggests, run it with the -r option:
    root:/var/lib/mysql/foobar# myisamchk -r cache_menu.MYI
    - recovering (with sort) MyISAM-table 'cache_menu.MYI'
    Data records: 0
    - Fixing index 1
    myisamchk: error: myisam_sort_buffer_size is too small
    MyISAM-table 'cache_menu.MYI' is not fixed because of errors
    Try fixing it by using the --safe-recover (-o), the --force (-f) option or by not using the --quick (-q) flag

    As you can see, I ran into a myisamchk: error: myisam_sort_buffer_size is too small (story of my life).
  4. To fix the buffer issue, an additional switch was required:
    root:/var/lib/mysql/foobar# myisamchk -r cache_menu.MYI --sort-buffer-size=1G
    - recovering (with sort) MyISAM-table 'cache_menu.MYI'
    Data records: 0
    - Fixing index 1
    - Fixing index 2
    Data records: 32641

The above steps did it. I am now able to make changes to my menu system without any issues and get back to saving the world.