更新挂起代码——Python MySQL连接器

更新挂起代码——Python MySQL连接器,python,mysql,sql-update,mysql-connector,freeze,Python,Mysql,Sql Update,Mysql Connector,Freeze,所以我试图更新一个表,由于某种原因,这段代码决定在执行时冻结 import mysql.connector cnx = mysql.connector.connect(user='user', password='password', host='y u so interested', database='discord') cursor = cnx.cursor() p

所以我试图更新一个表,由于某种原因,这段代码决定在执行时冻结

import mysql.connector

cnx = mysql.connector.connect(user='user', password='password',
                              host='y u so interested',
                              database='discord')

cursor = cnx.cursor()

print ("Start")

update = ("UPDATE admin_daily_playtime_crp1 "
        "SET DiscordName = %s "
        "WHERE SteamName = %s ")
values = ("true", "Modern Mo")
cursor.execute(update, values)
cnx.commit()

print ("done")
表格设置:

考虑更新您的表,以包含表中每列的正确数据类型。我将您的snipet更改为包含组织的功能。调用函数discorname(Discord Name,Steam Name),它应该更新信息。我在自己的数据库上测试了这个,效果很好

import mysql.connector



def connection():
    connection = mysql.connector.connect(user='root', password='', host='',database='discord')

    return connection

def discordName(discordName, steamName):
    con = connection()
    cursor = con.cursor()
    print ("Start")
    update = "UPDATE `admin_daily_playtime_crp1` SET `DiscordName` = %s WHERE `SteamName` = %s"
    cursor.execute(update, (discordName, steamName))
    print (cursor.rowcount, "record(s) affected!")
    con.commit()
如果你有更多的问题,尽管问吧!
这是我用过的新桌子的图片

我不明白,不知怎的它不再挂了。虽然您的代码确实有效,但非常感谢您的帮助!可能是数据库连接问题之类的。另外,尽量让变量的名称对它们的工作来说是显而易见的,这样其他人就可以更容易地阅读代码,而不必尝试和翻译它。并不是说你的代码不好,而是我想象你写的越多,它就越难理解。在我的例子中,没有任何回溯,仍然冻结-1.