Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

mysql

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.connector.errors.ProgrammingError: 1064 (4200): 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 '%s) at line 1.

This indicates a error in my code where I attempt to insert my variable np (VALUES (%s)");). np is a "noun-phrase" such as a "skate board".

import mysql.connector
from textblob import TextBlob

cnx = mysql.connector.connect(user='XXX', password='XXX',
                              host='XXXXX',
                              database='XXXX')

cursor = cnx.cursor(buffered=True)

Latest = ("SELECT * FROM SentAnalysis")
cursor.execute(Latest)

for row in cursor.fetchall():
    SentText = row[2]
    blob = TextBlob(SentText)
    for np in blob.noun_phrases:
        print(np)
        SQLInsertCmd = ("INSERT INTO TestNounPhrase (NPhrase) VALUES (%s)")
        cursor.execute(SQLInsertCmd,np)

cnx.commit()
cursor.close()
cnx.close()

The example from the manual is https://dev.mysql.com/doc/connector-python/en/connector-python-example-cursor-transaction.html. e.g.

 "VALUES (%s, %s, %s, %s, %s)")

I can't see a difference. This error is also discussed in detail here : How can I fix MySQL error #1064? Other similar examples on stackoverflow have been linked to reserved words, Redundant comas .But looking at these examples I can't spot an obvious error.

Any suggestions on where I am going wrong would be much appreciated.

like image 924
Steve Avatar asked Aug 13 '17 23:08

Steve


People also ask

What is the error in MySQL syntax?

During application update an error message containing "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 ..." appears in the log. It means your database is outdated and it can't work with the request our application sends to it.

How do I fix error 1064 42000?

The ERROR 1064 (42000) mainly occurs when the syntax isn't set correctly i.e. error in applying the backtick symbol or while creating a database without them can also create an error, if you will use hyphen in the name, for example, Demo-Table will result in ERROR 1064 (42000). Now database is created successfully.

How do I check the manual that corresponds to my MySQL server?

To check the MySQL version: In Windows, open cmd.exe as Administrator and run the following command: C:\Program Files\MySQL\MySQL Server x.x\bin\mysqld.exe -V . In Linux, open a command line and run the following command: mysql -V .


1 Answers

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

Have a good day.

like image 170
abhishek kumar Avatar answered Sep 19 '22 10:09

abhishek kumar