Advertisement
Guest User

Untitled

a guest
Jan 21st, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. import getpass
  2. from MySQLdb import connect
  3. password = getpass.getpass()
  4.  
  5. conn = connect(user="root", passwd=password)
  6. cur = conn.cursor()
  7.  
  8. cur.execute("SELECT table_schema, table_name, table_collation FROM information_schema.tables WHERE table_collation = 'utf8_unicode_ci' and table_schema='onsetsource';")
  9.  
  10. objs = cur.fetchall()
  11. db_to_update = objs[0][0]
  12. print "Updating %s db" % db_to_update
  13. print "-" * (12 + len(db_to_update))
  14. cur.execute("use %s" % db_to_update)
  15. for obj in objs:
  16. table_to_update = obj[1]
  17. print "Altering %s table" % table_to_update
  18. print "-" * (12 + len(table_to_update))
  19.  
  20. query = "ALTER TABLE %s CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;" % table_to_update
  21. cur.execute(query)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement