]> andersk Git - sql.git/blame - lib/python/sql/util.py
more old code
[sql.git] / lib / python / sql / util.py
CommitLineData
562fda3a
JP
1#!/usr/bin/python
2
3def get_backup_exceptions(path='/mit/sql/etc/db_no-daily-backup'):
4 return filter(len, map(str.strip, file(path).read().split('\n')))
5
6import MySQLdb, MySQLdb.cursors
7
8def use_db(cursor, db):
9 cursor.execute('USE `%s`' % db)
10
11def get_dbs(cursor):
12 cursor.execute('SHOW DATABASES')
13 return [x.values()[0] for x in cursor.fetchall() if x.values()[0] != 'information_schema']
14
15def get_db_tables(cursor, db):
16 cursor.execute('SHOW TABLES FROM `%s`' % db)
17 return [(db, x.values()[0]) for x in cursor.fetchall()]
18
19def get_db_tables_ft(cursor, db):
20 r = []
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']))
24 return r
25
26def 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()])
29
30def get_db_tables_engines(cursor, db):
31 return [(table, status['Engine']) for table, status in get_db_tables_status(cursor, db).items()]
32
33def 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)
37
38if __name__ == '__main__':
39 import sys
40
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):
44 # print table
45
46 #db = 'freeculture+youtomb'
47 #print get_db_tables_status(cursor, db)
48 #sys.exit(0)
49
50 while True:
51 data = sys.stdin.readline()
52 if not data:
53 break
54 data = data.strip()
55 table = eval(data)
56 print table
57 repair_table_quick(cursor, table)
This page took 0.16653 seconds and 5 git commands to generate.