Home  >  Q&A  >  body text

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 days ago637

reply all(1)I'll reply

  • 大家讲道理

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

    Set innodb_lock_wait_timeout according to your needs, the minimum can be 1 second.

    Waiting for one second will return an error message, but if you are in a programming language, 1 second is actually a relatively long time. In this case, you can control it in the program and set a shorter time through the program. Virtual "timeout", which takes into account network latency.

    reply
    0
  • Cancelreply