Advertisement
Guest User

Untitled

a guest
Nov 10th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import MySQLdb
  2. from sys import argv as sa
  3.  
  4. dbname="passwords"
  5. project=sa[1]
  6. infile=sa[2]
  7.  
  8. db = MySQLdb.connect(host="some.ip.tld", user="username", password="password")
  9. cur = db.cursor()
  10. try:
  11. cur.execute("create database " + str(dbname))
  12. except Exception as e:
  13. print e
  14. cur.execute("use " + str(dbname))
  15. try:
  16. cur.execute('CREATE TABLE '+str(project)+' (id INT NOT NULL AUTO_INCREMENT,email blob NOT NULL,user NOT NULL,domain blob NOT NULL,password blob NOT NULL,PRIMARY KEY (id));')
  17. except Exception as e:
  18. print e
  19. pass
  20. try:
  21. cur.execute('ALTER TABLE '+str(project)+' AUTO_INCREMENT = 1;')
  22. except Exception as e:
  23. print e
  24. pass
  25. db.commit()
  26. cur.close()
  27. db = MySQLdb.connect(host="some.ip.tld", user="username", password="password")
  28. #db = MySQLdb.connect(host="localhost", user="root")
  29. cur = db.cursor()
  30. try:
  31. cur.execute("use " + str(dbname))
  32. query='LOAD DATA LOCAL INFILE "'+infile+'" INTO TABLE '+str(project)+' FIELDS TERMINATED BY ":" (email, user, domain, password);'
  33. cur.execute(query)
  34. except Exception as e:
  35. print e
  36. pass
  37. db.commit()
  38. cur.close()
  39. print "Finished"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement