我尝试从CSV导入5列数据到MySQL表。MySQL第一列的autoincrement为空,第一列为空。下面的代码产生一个错误。在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()
此代码产生以下错误:
ProgrammingError:(1064,“您的SQL语法有错误;请查看与您的MySQL服务器版本对应的手册,了解使用接近'desc'值的正确语法('''Hoppy Brewing','-121.429684','38.554962','http://www.hoppy.'第1行“)