开发者

mysql table marked as crashed [closed]

开发者 https://www.devze.com 2022-12-25 07:35 出处:网络
Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed. This question is off-topic. It is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 10 years ago.

开发者_C百科 Improve this question

I recently created a ajax based instant messaging application and after running for a while I got an error [table] is marked as crashed and should be repaired. How could this have happened and how do I go about preventing it happening again?


http://www.pantz.org/software/mysql/fixingmysqlcrashedtables.html

For reference.. This command fixed my crashed tables, I had many:

sudo mysqlcheck --auto-repair -A -u root -p


This most of times happen on a crash of MySQL Server while it was writing on the table. You should try to run CHECK TABLE <databasename>.<tablename>, which will check the content of the table and ultimately let you know whether it's actually broken or not... Then you may need to run REPAIR TABLE <databasename>.<tablename>. You may also want to read a bit what's on that page.

If the table uses the MyISAM engine, you may as well use the myisamchk tool from the MySQL distribution (in which case I reckon you should refer back to that page).


This is not an answer but an example I have come up with that might help others:

function mysql_check_and_repair($array){
    if( is_array( $array ) ) {
        foreach( $array as $table_name ) {
            $q = mysql_query( "CHECK TABLE `$table_name` QUICK" ) or die( mysql_error() );
            $a = mysql_fetch_array( $q );
            if( $a['Msg_text'] != 'Table is already up to date' && $a['Msg_text'] != 'OK' ) {
                log_error( $a['Msg_text'] );
                mysql_query( "REPAIR TABLE `$table_name`" ) or die( mysql_query() );    
            }
        }
    }else{
        return false;
    }
}

Has anyone any indication on how ofter they think I should perform this ( currently doing before any updates are being made to the database but each request is 2 seconds )

0

精彩评论

暂无评论...
验证码 换一张
取 消