这是我的代码
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
使用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, " 条记录被修改")
语句写错了不支持这种写法