mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax;
Question:
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an
error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near ‘Name, Roll
Number, Email, Department, Biography, Insta_handle, Facebook_handle, ‘
at line 1
I am trying to upload a huge load of data into my sql server but its throwing an error. Can someone help me out? Here is the code:
name = df.Name[row]
first_name = df['First name'][0]
email = df['Email Address'][row]
roll = df['Roll Number'][row]
dept = df['Department'][row]
biography = df['Short Biography '][row]
insta = df['Instagram Handle'][row]
face = df['Facebook Handle'][row]
picture = name+'.jpg'
command = """INSERT INTO ismp(Name, First Name, Roll Number, Email, Department, Biography, Insta_handle, Facebook_handle, Picture_path)
VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')"""
data = (name, first_name,roll, email, dept,biography, insta, face, picture)
mycursor.execute(command, data)
mydb.commit()
break
I have also tried creating a new user with all the privileges with all the permission but still the error occured.
Answers:
You can use backticks to escape the blanks in the column names.
command = """INSERT INTO ismp(Name, `First Name`, `Roll Number`, Email,
Department, Biography, Insta_handle, Facebook_handle, Picture_path)
VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')"""
But better is to rename the columns without blanks.
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an
error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near ‘Name, Roll
Number, Email, Department, Biography, Insta_handle, Facebook_handle, ‘
at line 1
I am trying to upload a huge load of data into my sql server but its throwing an error. Can someone help me out? Here is the code:
name = df.Name[row]
first_name = df['First name'][0]
email = df['Email Address'][row]
roll = df['Roll Number'][row]
dept = df['Department'][row]
biography = df['Short Biography '][row]
insta = df['Instagram Handle'][row]
face = df['Facebook Handle'][row]
picture = name+'.jpg'
command = """INSERT INTO ismp(Name, First Name, Roll Number, Email, Department, Biography, Insta_handle, Facebook_handle, Picture_path)
VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')"""
data = (name, first_name,roll, email, dept,biography, insta, face, picture)
mycursor.execute(command, data)
mydb.commit()
break
I have also tried creating a new user with all the privileges with all the permission but still the error occured.
You can use backticks to escape the blanks in the column names.
command = """INSERT INTO ismp(Name, `First Name`, `Roll Number`, Email,
Department, Biography, Insta_handle, Facebook_handle, Picture_path)
VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')"""
But better is to rename the columns without blanks.