首頁  >  問答  >  主體

mysql优化 - 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的话,有没有什么替代的方案,求大神告知,感激不劲.

巴扎黑巴扎黑2742 天前639

全部回覆(1)我來回復

  • 大家讲道理

    大家讲道理2017-04-17 13:18:07

    依照你的需求設定innodb_lock_wait_timeout,最小可為1秒。

    等待一秒會回傳錯誤訊息,但是如果你是在程式語言中的話,1秒其實算是比較長的時間了,這種情況下,你可以在程式裡面控制,透過程式設定一個更短的虛擬的“超時時間”,這種情況要考慮網路延遲。

    回覆
    0
  • 取消回覆