Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 导入CSV到MySQL错误_Python_Mysql_Csv - Fatal编程技术网

Python 导入CSV到MySQL错误

Python 导入CSV到MySQL错误,python,mysql,csv,Python,Mysql,Csv,我正在尝试将5列数据从CSV导入MySQL表。MySQL的第一列是autoincrement,CSV的第一列是空白。下面的代码生成一个错误 import csv import MySQLdb database = MySQLdb.connect(host='10.200.10.125', user='spaine', passwd='spaine', db='scat') cursor = database.cursor() cursor.execute('show tables') fo

我正在尝试将5列数据从CSV导入MySQL表。MySQL的第一列是autoincrement,CSV的第一列是空白。下面的代码生成一个错误

import csv
import MySQLdb

database = MySQLdb.connect(host='10.200.10.125', user='spaine', passwd='spaine', db='scat')
cursor = database.cursor()


cursor.execute('show tables')
for row in cursor:
    print row

cursor.execute('describe brewpubs')
print "\n info about table brewpubs"

for row in cursor:
    print row

csv_file = 'E:\\Proving Grounds\\MsSQL Connection\\Brewery Data\\Breweries.csv'
csv_data = csv.reader(file(csv_file))


for row in csv_data:
    print row
    cursor.execute('''INSERT INTO brewpubs (PID, name, londd, latdd, desc) VALUES(%s, %s, %s, %s, %s)''', row)


database.commit()  # Make sure data is committed to the database

database.close()
此代码产生以下错误: 编程错误:(1064,“您的SQL语法有错误;请查看与您的MySQL服务器版本相对应的手册,以了解使用“desc”值附近的正确语法(“'Hoppy Brewing'”、'-121.429684'、'-38.554962'、'.'在第1行”)

desc在MySQL中是一个,您必须用倒勾(`)将其括起来作为标识符:

... (PID, name, londd, latdd, `desc`)

如果列是自动递增的,则从插入中完全忽略它,因为它始终为空。

您在哪里看到
文件(csv\u文件)
?由于它是第一列,您将如何忽略它?