
import csvimport MysqLdbmydb = MysqLdb.connect(host='localhost',user='root',passwd='',db='mydb')cursor = mydb.cursor()csv_data = csv.reader(file('students.csv'))for row in csv_data: cursor.execute('INSERT INTO testcsv(names,\ classes,mark )' \ 'VALUES("%s","%s","%s")',row)#close the connection to the database.cursor.close()print "Done" 如果有人能看一眼,我将不胜感激.
谢谢.
解决方法 我想你必须把mydb.commit()全部插入到.像这样的东西
import csvimport MysqLdbmydb = MysqLdb.connect(host='localhost',row)#close the connection to the database.mydb.commit()cursor.close()print "Done"总结
以上是内存溢出为你收集整理的用Python将CSV数据加载到MySQL中全部内容,希望文章能够帮你解决用Python将CSV数据加载到MySQL中所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)