It is a good idea to perform table checks on a regular basis
        rather than waiting for problems to occur. One way to check and
        repair MyISAM tables is with the
        CHECK TABLE and
        REPAIR TABLE statements. These
        are available starting with MySQL 3.23.16. See
        Section 12.4.2, “Table Maintenance Statements”.
      
        Another way to check tables is to use
        myisamchk. For maintenance purposes, you can
        use myisamchk -s. The -s
        option (short for --silent)
        causes myisamchk to run in silent mode,
        printing messages only when errors occur.
      
        It is also a good idea to check tables when the server starts.
        For example, whenever the machine has done a restart in the
        middle of an update, you usually need to check all the tables
        that could have been affected. (These are
        “expected” crashed tables.) To cause the server to
        check MyISAM tables automatically, start it
        with the --myisam-recover option,
        available as of MySQL 3.23.25. If your server is too old to
        support this option, you could add a test to
        mysqld_safe that runs
        myisamchk to check all tables that have been
        modified during the last 24 hours if there is an old
        .pid (process ID) file left after a
        restart. (The .pid file is created by
        mysqld when it starts and removed when it
        terminates normally. The presence of a .pid
        file at system startup time indicates that
        mysqld terminated abnormally.)
      
        It is also a good idea to enable automatic
        MyISAM table checking. For example, whenever
        the machine has done a restart in the middle of an update, you
        usually need to check each table that could have been affected
        before it is used further. (These are “expected crashed
        tables.”) To check MyISAM tables
        automatically, start the server with the
        --myisam-recover option,
        available as of MySQL 3.23.25. See
        Section 5.1.2, “Server Command Options”. If your server is too old to
        support this option, you could add a test to
        mysqld_safe that runs
        myisamchk to check all tables that have been
        modified during the last 24 hours if there is an old
        .pid (process ID) file left after a
        restart. (The .pid file is created by
        mysqld when it starts and removed when it
        terminates normally. The presence of a .pid
        file at system startup time indicates that
        mysqld terminated abnormally.)
      
        You should also check your tables regularly during normal system
        operation. For example, you can run a cron
        job to check important tables once a week, using a line like
        this in a crontab file:
      
35 0 * * 0/path/to/myisamchk--fast --silent/path/to/datadir/*/*.MYI
This prints out information about crashed tables so that you can examine and repair them as necessary.
To start with, execute myisamchk -s each night on all tables that have been updated during the last 24 hours. As you see that problems occur infrequently, you can back off the checking frequency to once a week or so.
        Normally, MySQL tables need little maintenance. If you are
        performing many updates to MyISAM tables with
        dynamic-sized rows (tables with
        VARCHAR,
        BLOB, or
        TEXT columns) or have tables with
        many deleted rows you may want to defragment/reclaim space from
        the tables from time to time. You can do this by using
        OPTIMIZE TABLE on the tables in
        question. Alternatively, if you can stop the
        mysqld server for a while, change location
        into the data directory and use this command while the server is
        stopped:
      
shell> myisamchk -r -s --sort-index --sort_buffer_size=16M */*.MYI
        For ISAM tables, the command is similar:
      
shell> isamchk -r -s --sort-index -O sort_buffer_size=16M */*.ISM


User Comments
Add your own comment.