Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. import pymysql.cursors
  2.  
  3. # Connect to the database
  4. connection = pymysql.connect(host='localhost',
  5. user='user',
  6. password='password',
  7. db='dbname',
  8. charset='utf8mb4',
  9. cursorclass=pymysql.cursors.DictCursor)
  10.  
  11. try:
  12. with connection.cursor() as cursor:
  13. with open('temp.txt') as file:
  14. for line in file:
  15. query = "DROP TABLE IF EXISTS " + line
  16. cursor.execute(query)
  17. connection.commit()
  18.  
  19. finally:
  20. connection.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement