save csv file into mysql in python code example
Example 1: 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()
Example 2: how to dump .csv file into mysql
LOAD DATA LOCAL INFILE 'c:/country.csv'
INTO TABLE country
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;