Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Previously, I use this:

USE dbname;
ALTER TABLE tablename ENGINE=MYISAM;

I'm looking for simpler way to convert all tables in a database, rather than writing every table name one by one

share|improve this question
    
Simpler how? That looks pretty simple to me. –  Zoredache Mar 10 '11 at 15:58
4  
Learn to use scripting to accomplish your goals. –  Tom O'Connor Mar 10 '11 at 16:15
add comment

2 Answers 2

I'm not aware of any way to do this in mysql itself, but a simple shell script will do the job:

TABLES=$(mysql -pXXXXXXX -uXXXXXXX --skip-column-names -B -D $DB -e 'show tables')
for T in $TABLES
do
    mysql -pXXXXX -uXXXXX -D $DB -e "ALTER TABLE $T ENGINE=MYISAM"
done
share|improve this answer
add comment

You can use MySQL to script it and execute it:

This will convert every InnoDB table in database dbname to MyISAM

CONVERT_SCRIPT=Convert_dbname_InnoDB_to_MyISAM.sql
mysql -u... -p... -AN -e"SELECT CONCAT('ALTER TABLE ',table_schema,'.',table_name,' ENGINE=MyISAM;') FROM information_schema.tables WHERE table_schema='dbname' AND engine='InnoDB';" > ${CONVERT_SCRIPT}
mysql -u... -p... -A < ${CONVERT_SCRIPT}

This will convert every InnoDB table to MyISAM

CONVERT_SCRIPT=Convert_InnoDB_to_MyISAM.sql
mysql -u... -p... -AN -e"SELECT CONCAT('ALTER TABLE ',table_schema,'.',table_name,' ENGINE=MyISAM;') FROM information_schema.tables WHERE engine ='InnoDB';" > ${CONVERT_SCRIPT}
mysql -u... -p... -A < ${CONVERT_SCRIPT}

If you do not want the conversion of the tables to be replicated to Slaves, just put SET SQL_LOG_BIN=0; as the first line. That way, you can test the conversion in a Master/Slave setup by converting only the Slave first and then the Master later.

This will convert every InnoDB table in database dbname to MyISAM and not replicate to other servers

CONVERT_SCRIPT=Convert_dbname_InnoDB_to_MyISAM.sql
echo "SET SQL_LOG_BIN=0;" > ${CONVERT_SCRIPT}
mysql -u... -p... -AN -e"SELECT CONCAT('ALTER TABLE ',table_schema,'.',table_name,' ENGINE=MyISAM;') FROM information_schema.tables WHERE table_schema='dbname' AND engine='InnoDB';" >> ${CONVERT_SCRIPT}
mysql -u... -p... -A < ${CONVERT_SCRIPT}

This will convert every InnoDB table to MyISAM and not replicate to other servers

CONVERT_SCRIPT=Convert_InnoDB_to_MyISAM.sql
echo "SET SQL_LOG_BIN=0;" > ${CONVERT_SCRIPT}
mysql -u... -p... -AN -e"SELECT CONCAT('ALTER TABLE ',table_schema,'.',table_name,' ENGINE=MyISAM;') FROM information_schema.tables WHERE engine ='InnoDB';" >> ${CONVERT_SCRIPT}
mysql -u... -p... -A < ${CONVERT_SCRIPT}

Give it a Try !!!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.