mysql.connector.errors.ProgrammingError: 1064 (4200): You have an error in your SQL syntax;

前端 未结 7 1961
暖寄归人
暖寄归人 2021-01-03 01:02

I am attempting to insert data into a MySQL database. I am using python 2.7 and I am using the mysql.connector.

My error is:

mysql.connecto

相关标签:
7条回答
  • 2021-01-03 01:35

    I was getting same error and while searching for its solution I stumbled upon this question after several attempts I was able to resolve. The mistake was a typing error for column name in WHERE clause of UPDATE statement. My column name was 'ROLL_NO' instead I had typed 'ROLL_NO.' Please look to this point as well.

    0 讨论(0)
  • 2021-01-03 01:38

    str parameter in SQL query must by in quote 'str'.
    So, need use '%s' with ' ' for str, and %s without ' ' for numbers:

    cursor.execute("""INSERT INTO db_name (str,int,str,int)
                      VALUES ('%s', %s, '%s', %s)""" % (str,int,str,int))
    cnx.commit()
    
    0 讨论(0)
  • 2021-01-03 01:44

    mycursor.execute("insert into table_name(column) values(%s)"%data_variable)

    0 讨论(0)
  • 2021-01-03 01:46

    I think the issue here might be the semicolon at the end of the query.

    Have a good day.

    0 讨论(0)
  • 2021-01-03 01:48

    I had the same issue with the single parameter statement, this worked:

    mycursor.execute("INSERT INTO cust (user) VALUES(%s)" % (username))
    
    0 讨论(0)
  • 2021-01-03 01:52

    Try this

    SQLInsertCmd = """INSERT INTO
                      TestNounPhrase (NPhrase) VALUES ((%s))"""  % (np)
    cursor.execute(SQLInsertCmd)
    
    0 讨论(0)
提交回复
热议问题