python-connector-mysql库的execute()

这是我的代码


if __name__=='__main__':
    connection_f()

    sql_use_db="USE {}的信息".format(user_name)
    add_new_tablehead_and_type_sql = "ALTER TABLE %s CHANGE %s %s %s;"
    cursor=connection.cursor()
    cursor.execute(sql_use_db)
    cursor.execute(add_new_tablehead_and_type_sql,('密码表管理','账号','我的账号','TEXT'))
    cursor.close()

    connection.close()

以下是错误信息:
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 ''密码表管理' CHANGE '账号' '我的账号' 'TEXT'' at line 1

不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 帮你找了个相似的问题, 你可以看下: https://ask.csdn.net/questions/7398124
  • 除此之外, 这篇博客: Python MySQL驱动--mysql-connector中的 11、更新表数据 部分也许能够解决你的问题, 你可以仔细阅读以下内容或者直接跳转源博客中阅读:

    使用UPDATE语句

    import mysql.connector
     
    mydb = mysql.connector.connect(
      host="localhost",
      user="root",
      passwd="123456",
      database="runoob_db"
    )
    mycursor = mydb.cursor()
     
    sql = "UPDATE sites SET name = 'ZH' WHERE name = 'Zhihu'"
     
    mycursor.execute(sql)
     
    mydb.commit()
     
    print(mycursor.rowcount, " 条记录被修改")

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^

语句写错了不支持这种写法