#!/usr/bin/python def get_backup_exceptions(path='/mit/sql/etc/db_no-daily-backup'): return filter(len, map(str.strip, file(path).read().split('\n'))) import MySQLdb, MySQLdb.cursors def use_db(cursor, db): cursor.execute('USE `%s`' % db) def get_dbs(cursor): cursor.execute('SHOW DATABASES') return [x.values()[0] for x in cursor.fetchall() if x.values()[0] != 'information_schema'] def get_db_tables(cursor, db): cursor.execute('SHOW TABLES FROM `%s`' % db) return [(db, x.values()[0]) for x in cursor.fetchall()] def get_db_tables_ft(cursor, db): r = [] for table in get_db_tables(cursor, db): cursor.execute('SHOW INDEXES FROM `%s`.`%s`' % table) r.extend(set([(db, x['Table']) for x in cursor.fetchall() if x['Index_type'] == 'FULLTEXT'])) return r def get_db_tables_status(cursor, db): cursor.execute('SHOW TABLE STATUS FROM `%s`' % db) return dict([((db, x['Name']), x) for x in cursor.fetchall()]) def get_db_tables_engines(cursor, db): return [(table, status['Engine']) for table, status in get_db_tables_status(cursor, db).items()] def repair_table_quick(cursor, table): # REPAIR TABLE tbl QUICK # works when changing ft_min_word_len cursor.execute('REPAIR TABLE `%s`.`%s` QUICK' % table) if __name__ == '__main__': import sys cursor = MySQLdb.connect('localhost', read_default_group='client', cursorclass=MySQLdb.cursors.DictCursor).cursor() #for db in get_dbs(cursor): # for table in get_db_tables_ft(cursor, db): # print table #db = 'freeculture+youtomb' #print get_db_tables_status(cursor, db) #sys.exit(0) while True: data = sys.stdin.readline() if not data: break data = data.strip() table = eval(data) print table repair_table_quick(cursor, table)