3 def get_backup_exceptions(path='/mit/sql/etc/db_no-daily-backup'):
4 return filter(len, map(str.strip, file(path).read().split('\n')))
6 import MySQLdb, MySQLdb.cursors
8 def use_db(cursor, db):
9 cursor.execute('USE `%s`' % db)
12 cursor.execute('SHOW DATABASES')
13 return [x.values()[0] for x in cursor.fetchall() if x.values()[0] != 'information_schema']
15 def get_db_tables(cursor, db):
16 cursor.execute('SHOW TABLES FROM `%s`' % db)
17 return [(db, x.values()[0]) for x in cursor.fetchall()]
19 def get_db_tables_ft(cursor, db):
21 for table in get_db_tables(cursor, db):
22 cursor.execute('SHOW INDEXES FROM `%s`.`%s`' % table)
23 r.extend(set([(db, x['Table']) for x in cursor.fetchall() if x['Index_type'] == 'FULLTEXT']))
26 def get_db_tables_status(cursor, db):
27 cursor.execute('SHOW TABLE STATUS FROM `%s`' % db)
28 return dict([((db, x['Name']), x) for x in cursor.fetchall()])
30 def get_db_tables_engines(cursor, db):
31 return [(table, status['Engine']) for table, status in get_db_tables_status(cursor, db).items()]
33 def repair_table_quick(cursor, table):
34 # REPAIR TABLE tbl QUICK
35 # works when changing ft_min_word_len
36 cursor.execute('REPAIR TABLE `%s`.`%s` QUICK' % table)
38 if __name__ == '__main__':
41 cursor = MySQLdb.connect('localhost', read_default_group='client', cursorclass=MySQLdb.cursors.DictCursor).cursor()
42 #for db in get_dbs(cursor):
43 # for table in get_db_tables_ft(cursor, db):
46 #db = 'freeculture+youtomb'
47 #print get_db_tables_status(cursor, db)
51 data = sys.stdin.readline()
57 repair_table_quick(cursor, table)