Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import MySQLdb
- class Database:
- def __init__(self):
- self.host = 'localhost'
- self.user = 'root'
- self.port = 3306
- self.password = 'root'
- self.db = 'test'
- self.connection = MySQLdb.connect(self.host, self.user, self.password, self.db, self.port, local_infile = 1)
- self.cursor = self.connection.cursor()
- def insert_csv_test(self):
- query = "LOAD DATA LOCAL INFILE ‘/Users/ankr/Desktop/output’ INTO TABLE details FIELDS TERMINATED BY ‘,’ LINES TERMINATED BY ‘n’"
- self.cursor.execute(query)
- self.connection.commit()
- self.connection.close()
- print("Done")
- def close_connection(self):
- self.connection.close()
- database = Database()
- database.__init__()
- database.insert_csv_test()
- database.close_connection()
Add Comment
Please, Sign In to add comment