Advertisement
Guest User

Untitled

a guest
Jul 15th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. import MySQLdb as mdb
  2.  
  3. import datetime, time
  4.  
  5. def run_sql_file(filename, connection):
  6. start = time.time()
  7.  
  8. file = open(filename, 'r')
  9. sql = s = " ".join(file.readlines())
  10. print ("Start executing: " + filename + " at " + str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M")) + "\n" + sql )
  11. cursor = connection.cursor()
  12. cursor.execute(sql)
  13. connection.commit()
  14.  
  15. end = time.time()
  16. print ("Time elapsed to run the query:")
  17. print (str((end - start)*1000) + ' ms')
  18.  
  19.  
  20.  
  21. def main():
  22. connection = mdb.connect('127.0.0.1', 'root', 'admin', 'dbcrawlermerlot')
  23. run_sql_file("DBMERLOT-04-2015.sql", connection)
  24. connection.close()
  25.  
  26. if __name__ == "__main__":
  27. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement