0

我在 Debian Squeezy 上使用 1.2.2 MySQLdb 和 Python 2.6.6 和 MariaDB 5.5.30。所有表都使用 MyIsam 引擎。

我的代码正在将一些数据写入临时表,然后将其插入永久表并在此之后截断 temp。因此,临时表是某种缓冲区。

有时(经常,但并非总是)它会在截断时冻结。MySQL 命令行客户端显示它正在等待表元数据锁定。没有其他可能锁定表的进程。

MariaDB [torgi]> show processlist;
+-----+------+-----------+-------+---------+------+---------------------------------+------------------------------+----------+
| Id  | User | Host      | db    | Command | Time | State                           | Info                         | Progress |
+-----+------+-----------+-------+---------+------+---------------------------------+------------------------------+----------+
| 194 | root | localhost | torgi | Sleep   |   29 |                                 | NULL                         |    0.000 |
| 195 | root | localhost | torgi | Query   |   29 | Waiting for table metadata lock | TRUNCATE `notifications_new` |    0.000 |
| 196 | root | localhost | torgi | Query   |    0 | NULL                            | show processlist             |    0.000 |
+-----+------+-----------+-------+---------+------+---------------------------------+------------------------------+----------+
3 rows in set (0.00 sec)

我试图打开自动提交,手动提交或刷新表(见注释行)。两者都没有帮助。

这是代码:

def upt(table, con) :
    #con.autocommit(True)
    cur = con.cursor()
    cur.execute('REPLACE INTO `'+table+suffix+'` select * from `'+table+tmp_suffix+'`;')
    #cur.execute('FLUSH tables;')
    #con.commit()
    cur.execute('TRUNCATE `'+table+tmp_suffix+'`;') # Freeze here!

那么,为什么它会被锁定以及如何修复它?

4

0 回答 0