简体   繁体   English

您的 SQL 语法有错误; 检查与您的 MySQL 服务器 PYTHON 相对应的手册

[英]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server PYTHON

I'm trying to insert some variables into my database, but I'm getting this error, I don't know what I'm doing wrong, could you help me?我正在尝试将一些变量插入到我的数据库中,但是我收到了这个错误,我不知道我做错了什么,你能帮我吗? Thanks in advance提前致谢

import mysql.connector as co
import time as tm
dbConnect = {
    'host':'mx102.hostgator.mx',
    'port':'3306',
    'user':'meandmic_root',
    'password':'abcde',
    'database':'meandmic_analizador'
}

felicidad = 0
enojo = 0
sorpresa = 0
tristeza = 0
neutral = 0
dt = tm.strftime("%d/%m/%y")
conexion = co.connect(**dbConnect)
cursor = conexion.cursor()
sqlInsertar = "insert into registros(CFELICIDAD,CENOJO,CSORPRESA,CTRISTEZA,CNEUTRAL,FECHA)values(%s,%s,%s,%s,%s,%s)"
cursor.execute(sqlInsertar,[felicidad,enojo,sorpresa,tristeza,neutral,dt])
conexion.commit()

尝试将您的列表更改为元组:

cursor.execute(sqlInsertar,(felicidad,enojo,sorpresa,tristeza,neutral,dt))

As Mikhail Ilin mentioned, the cursor.execute method expects a tuple as the second parameter.正如 Mikhail Ilin 提到的, cursor.execute方法需要一个元组作为第二个参数。

The official documentation 6.9.5.4 MySQLCursor.execute() Method has an example query that is very similar to yours.官方文档6.9.5.4 MySQLCursor.execute() 方法有一个示例查询,与您的非常相似。

insert_stmt = (
   "INSERT INTO employees (emp_no, first_name, last_name, hire_date) "
   "VALUES (%s, %s, %s, %s)"
)
data = (2, 'Jane', 'Doe', datetime.date(2012, 3, 23))
cursor.execute(insert_stmt, data)

In this example, data is a tuple , not a list .在这个例子中, data是一个tuple ,而不是一个list

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 42000您的SQL语法错误; 检查与您的MySQL服务器相对应的手册 - 42000 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server 您的 SQL 语法有错误; 检查与您的 MySQL 服务器版本相对应的手册,以获取在 ') 附近使用的正确语法 - 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 ') “你的SQL语法有错误; 查看与您的MySQL服务器版本对应的手册,以便在''第1行'附近使用正确的语法 - “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 '' at line 1” 警告:您的SQL语法有错误; 查看与您的MySQL服务器版本对应的手册,以便在附近使用正确的语法 - Warning: 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 您的 SQL 语法有错误; 检查与您的 MySQL 服务器版本相对应的手册,以获取在 \'keyword")\' 附近使用的正确语法 - 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 \'keyword")\' 1064(42000):您的 SQL 语法有错误; 检查与您的 MySQL 服务器版本相对应的手册,以获取正确的语法使用 - 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 您的 SQL 语法有错误; 检查与您的 MySQL 服务器版本相对应的手册,以获取在 '*) 附近使用的正确语法 - 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 '*) 您的SQL语法有错误; 检查与您的MariaDB服务器版本对应的手册,以便在第1行附近使用正确的语法, - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near at line 1", MYSQL 数据库错误:“pymysql.err.ProgrammingError: (1064, ”您的 SQL 语法有错误;请查看与您对应的手册-" - MYSQL Database error: “pymysql.err.ProgrammingError: (1064, ”You have an error in your SQL syntax; check the manual that corresponds to your-" sqlalchemy.exc.ProgrammingError:您的SQL语法有错误; 查看与MariaDB服务器版本对应的手册 - sqlalchemy.exc.ProgrammingError: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM