Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 更新现有sql数据库_Python_Mysql_Sql Update - Fatal编程技术网

Python 更新现有sql数据库

Python 更新现有sql数据库,python,mysql,sql-update,Python,Mysql,Sql Update,我所有的价值都以列表的形式存在my_list=[…][…]等] 我设置了一个函数来更新现有数据库中的一些值 def sql_update(my_list_int): #my_list_int is an integer value that would call the list that I need db = MySQLdb.connect(host = 'my_host', user = 'my_user', passw='my_

我所有的价值都以列表的形式存在
my_list=[…][…]等]

我设置了一个函数来更新现有数据库中的一些值

def sql_update(my_list_int): #my_list_int is an integer value that would call the list that I need
    db = MySQLdb.connect(host = 'my_host', user = 'my_user', 
                         passw='my_pass', dd='my_db')

    sql = """UPDATE my_database SET col2 = %s WHERE col1 = %s"""

    cursor.execute(sql, (my_list[%s][2], my_list[%s][1] )) 

    db.commit()
    cursor.close()
my\u list\u int=0
1
2
时,一切都会运行。但对于我得到的任何其他价值

操作错误:(1205,“超过锁定等待超时”)

当我立即再次运行它而没有任何更改时

IntegrityError:(1062,“重复条目”)


我不知道我的错误在哪里

你是在循环中运行这段代码吗?最终我会,但现在我只是像
sql\u update(1)
一样以单行的形式运行它。对于0,1,2,可能需要调试问题:。直接在mysql(thourgh phpmyadmin)上运行sql查询,我认为您更新的记录太多,请使用相同的条件执行select,然后查看将返回多少条记录。我正在更新1条记录。事实上,我有一个类似的函数,它最初将所有内容加载到mysql中,并且工作正常。