You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MariaDB中GET_LOCK()如何设置无限超时?MySQL支持负超时值实现

Handling Infinite Timeout with GET_LOCK(): MySQL vs MariaDB

Let's break down the behavior and key differences between MySQL and MariaDB when working with GET_LOCK() for infinite timeout scenarios:

MySQL's Native Support

  • In MySQL, you can natively achieve an infinite timeout with GET_LOCK() by passing a negative value for the timeout parameter. The official documentation clearly states:

    GET_LOCK()尝试获取由字符串str指定名称的锁,超时时间为timeout秒,负超时值表示无限超时。

  • This lock is exclusive: once a session holds it, no other session can acquire the same named lock until it’s released—either explicitly via RELEASE_LOCK(), or automatically when the holding session disconnects.

MariaDB's Current Limitation

  • Unlike MySQL, MariaDB's official documentation does not mention support for negative timeout values in GET_LOCK() to enable infinite waiting. There’s no explicitly documented, direct way to replicate this "infinite timeout" behavior using the function in MariaDB.

Practical Workaround for MariaDB

If you need a close approximation of infinite waiting in MariaDB, you can use an extremely large positive timeout value (e.g., 31536000, which equals one year in seconds) as a substitute. While this isn’t truly infinite, it’s a practical stand-in for most use cases where you need the lock wait to persist indefinitely under normal operating conditions.

内容的提问来源于stack exchange,提问作者BigHelmet

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 02:30:00