Guest User

Untitled

a guest
Oct 18th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import MySQLdb
  3.  
  4. class Database:
  5.  
  6. def __init__(self):
  7.  
  8. self.host = 'localhost'
  9. self.user = 'root'
  10. self.port = 3306
  11. self.password = 'root'
  12. self.db = 'test'
  13. self.connection = MySQLdb.connect(self.host, self.user, self.password, self.db, self.port, local_infile = 1)
  14. self.cursor = self.connection.cursor()
  15.  
  16.  
  17. def insert_csv_test(self):
  18.  
  19. query = "LOAD DATA LOCAL INFILE ‘/Users/ankr/Desktop/output’ INTO TABLE details FIELDS TERMINATED BY ‘,’ LINES TERMINATED BY ‘n’"
  20. self.cursor.execute(query)
  21. self.connection.commit()
  22. self.connection.close()
  23. print("Done")
  24.  
  25. def close_connection(self):
  26. self.connection.close()
  27.  
  28. database = Database()
  29. database.__init__()
  30. database.insert_csv_test()
  31. database.close_connection()
Add Comment
Please, Sign In to add comment