Python Script to convert MyISAM Engine to InnoDB of specific tables in MySQL

Hello Friends,

I have created a script that will change your database engine of Specific Tables, not all.  


Make necessary changes, My username is root, password is 123456 and database name is dawn

1. It asks for table name.

2. It takes dump of table without data and with triggers

3. It make changes in .sql file to make it InnoDB.

4. It dumps data

5. It restores the file of step 3. 

6. It restores the file of step 4. ( data )

7. It asks the name of next table.

8. This works on Python 2.x. Please test it before running on production.


import fileinput
import os
while True:
    table = raw_input('Enter the name of table ')
    cmd1='mysqldump -u root -p123456 --no-data -R --triggers dawn ' + table+ ' > '+table+'.sql'
    fname= table+'.sql'
    print fname
    for line in fileinput.FileInput(fname, inplace=1):
        line= line.replace('MyISAM', 'InnoDB')
        print line,
    cmd2='mysqldump -u root -p123456 --no-create-info -R --triggers dawn ' + table + ' > '+table+'_data.sql'
    print cmd2
    cmd3='mysql -p123456 dawn < '+table+'.sql'
    print cmd3
    cmd4='mysql -p123456 dawn < '+table+'_data.sql'
    print cmd4
    print 'Conversion successful for ' + table