insert csv mysql code example
Example 1: mysql load csv into table
LOAD DATA INFILE 'c:/tmp/discounts.csv'
INTO TABLE discounts
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;
Example 2: python mysql insert csv
# Insert DataFrame to Table
for row in df.itertuples():
cursor.execute('''
INSERT INTO TestDB.dbo.people_info (Name, Country, Age)
VALUES (?,?,?)
''',
row.Name,
row.Country,
row.Age
)
conn.commit()