首页 > MySQL中的for update nowait

MySQL中的for update nowait

MySQL中是不是不支持nowait,有如下语句

select * from table_name for update nowait;

执行完报错,语法错误

mysql> select * from t_needs_word where word_type="N" for update nowait;
1064 - 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 'nowait' at line 1

这个有什么解决方案吗? 还有MySQL如果我默认使用InnoDB引擎,一个表中如果没有主键,是不是就不支持行锁了,而变成了表锁.我测试下来,是这样的.
如果MySQL不支持nowait的话,有没有什么替代的方案,求大神告知,感激不劲.


根据你的需要设置innodb_lock_wait_timeout,最小可为1秒。

等待一秒会返回错误信息,但是如果你是在编程语言中的话,1秒其实算是比较长的时间了,这种情况下,你可以在程序里面控制,通过程序设置一个更短的虚拟的“超时时间”,这种情况要考虑网络延迟。

【热门文章】
【热门文章】