第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如果MySQL數(shù)據(jù)庫連接池在很長一段時(shí)間內(nèi)未使用,或者使用它的應(yīng)用程序崩潰了,那么它是否會(huì)過期?

如果MySQL數(shù)據(jù)庫連接池在很長一段時(shí)間內(nèi)未使用,或者使用它的應(yīng)用程序崩潰了,那么它是否會(huì)過期?

撒科打諢 2022-08-02 18:18:10
我正在使用從Python腳本連接數(shù)據(jù)庫MySQL(MariaDB)。我使用上下文管理器來連接池中的連接。我想知道如果長時(shí)間不使用或我的程序崩潰,池是否會(huì)過期。我發(fā)現(xiàn)與MySQL數(shù)據(jù)庫的連接過期,即使您忘記或無法在程序中關(guān)閉連接,它也會(huì)被釋放嗎,連接池的情況如何?MySQLConnectionPoolfrom contextlib import contextmanagerimport mysql.connectorfrom mysql.connector.errors import Errorfrom mysql.connector import poolingSQL_CONN_POOL = pooling.MySQLConnectionPool(    pool_name="mysqlpool",    pool_size=1,    user=DB_USER,    password=DB_PASS,    host=DB_HOST,    database=DATABASE,    auth_plugin=DB_PLUGIN)@contextmanagerdef mysql_connection_from_pool() -> "conn":    conn_pool = SQL_CONN_POOL  # get connection from the pool, all the rest is the same    _conn = conn_pool.get_connection()    try:        yield _conn    except (Exception, Error) as ex:        # if error happened all made changes during the connection will be rolled back:        _conn.rollback()        # this statement re-raise error to let it be handled in outer scope:        raise    else:        # if everything is fine commit all changes to save them in db:        _conn.commit()    finally:        # actually it returns connection to the pool, rather than close it        _conn.close()@contextmanagerdef mysql_curs_from_pool() -> "curs":    with mysql_connection_from_pool() as _conn:        _curs = _conn.cursor()        try:            yield _curs        finally:            _curs.close()
查看完整描述

1 回答

?
慕村9548890

TA貢獻(xiàn)1884條經(jīng)驗(yàn) 獲得超4個(gè)贊

是的,它可以超時(shí)。有兩種超時(shí)配置。

查看wait_timeoutinteractive_timeout


查看完整回答
反對(duì) 回復(fù) 2022-08-02
  • 1 回答
  • 0 關(guān)注
  • 248 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)