mysql python错误1064,mysql sytax错误

dbf7pr2w  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(468)

我现在有一些问题,当我试图插入一行到一个数据库,这也工作过,虽然它只是现在,我已经添加了“键”列,它无法工作,并给我一个错误。

  1. add = ("INSERT INTO server_stats_servers "
  2. "(Owner, ServerID, MessageID, Channel, ServerIP, ServerPort, ServerName, DiscordName, Key)"
  3. "VALUES (%(Owner)s, %(ServerID)s, %(MessageID)s, %(Channel)s, %(ServerIP)s, %(ServerPort)s, %(ServerName)s, %(DiscordName)s, %(Key)s)")
  4. values = {"Owner": owner,
  5. "ServerID": serverid,
  6. "MessageID": messageid,
  7. "Channel": channel,
  8. "ServerIP": ip,
  9. "ServerPort": port,
  10. "ServerName": servername,
  11. "DiscordName": discordname,
  12. "Key": key,}
  13. cursor.execute(add, values)
  14. cnx.commit()

错误:

  1. 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 ''Key')VALUES ('Modern_Mo', '349692657221500938', '505375472646094868', '48783440' at line 1

任何帮助都太好了!所有这些输入都是字符串,“key”指定为“modern”)

wsxa1bj1

wsxa1bj11#

KEY 是mysql中的保留字。当用作标识符时,必须在查询中引用它:

  1. add = ("INSERT INTO server_stats_servers (Owner, ServerID, MessageID, "
  2. "Channel, ServerIP, ServerPort, ServerName, DiscordName, `Key`) "
  3. "VALUES (%(Owner)s, %(ServerID)s, %(MessageID)s, %(Channel)s, "
  4. "%(ServerIP)s, %(ServerPort)s, %(ServerName)s, %(DiscordName)s, %(Key)s)")

相关问题