Showing posts with label MyISAM. Show all posts
Showing posts with label MyISAM. Show all posts

Monday, 28 May 2012

MySQL database repair - myisamchk

Hi,

To check/repair MySQL database which using the database engine MyISAM, we can use the command "myisamchk" . Syntacx is as given below :

 To check the status :

myisamchk /var/lib/mysql/DATABASE_NAME/*.MYI

This will displays the tables that should be repaired.

To repair the whole database,

myisamchk --silent --force --fast --update-state /var/lib/mysql/DATABASE_NAME/*.MYI

To repair a single table:

myisamchk -r /var/lib/mysql/DATABASE_NAME/TABLE_NAME.MYI


Tuesday, 8 May 2012

Convert InnoDB TO MyISAM Script

Hi,

To convert InnoDB to MyISAM, you can use the following script. This is applicable for a single database. Stop Apache before doing this.

=======================
 #/bin/bash
#script to convert the whole database to myisam format.
cp -iRfp /var/lib/mysql /var/lib/mysql-$(date +%s)
for DATABASE_NAME in $(mysql --batch --column-names=false -e "show databases");
do
for t in $(mysql --batch --column-names=false -e "show tables" $DATABASE_NAME);
do
mysql -e "alter table $t type=MyIsam" $DATABASE_NAME;
echo "converted "$t" to MyIsam"
done
done 
========================

Thanks.