import pymysql
import pandas as pd
import sys
load_sql= "LOAD DATA LOCAL INFILE
'C:/Users/ksureshb/Documents/Masterdata1.csv' INTO TABLE as.iris_master
FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n'; "
host="localhost"
def csv_to_mysql(load_sql, host="localhost", user="root", passwd="",database="as"):
'''
This function load a csv file to MySQL table according to
the load_sql statement.
'''
print("code started")
con = pymysql.connect(host="localhost",
user="root",
password="",
autocommit=True,
local_infile=1)
print('Connected to DB: {}'.format(host))
# Create cursor and execute Load SQL
cursor = con.cursor()
cursor.execute(load_sql)
print('Succuessfully loaded the table from csv.')
con.close()
代码执行得很好。 CSV文件约有200000行,只有第一行反映在mysql数据库中。任何帮助将不胜感激。