共計 2329 個字符,預計需要花費 6 分鐘才能閱讀完成。
MySQLump 中 Lock-Tables 參數的作用是什么,針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
mysqldump 有一個參數 –lock-tables,以前對這個參數也沒有深入、詳細了解過,直到上次有個網友問“參數 lock-tables 是一次性鎖定當前庫的所有表,還是鎖定當前導出表?“,之前一直以為只是鎖定當前導出表,后面看了參數說明后,
-l, --lock-tables Lock all tables for read. (Defaults to on; use --skip-lock-tables to disable.)
自己也不怎么確認了,當時就測試了一下。準備一個稍微大一點的庫,如果數據庫太小,那么可能 mysqldum 命令一下子就導出了所有庫,很難清晰的看到實驗結果。
執行下面命令做邏輯備份
[root@DB-Server ~]# mysqldump -u root -p --default-character-set=utf8 --opt --extended-insert=false --lock-tables MyDB db_backup_MyDB.sql Enter password:
同時立即執行下面命令
mysql show open tables where in_use +----------+--------------------------------+--------+-------------+ | Database | Table | In_use | Name_locked | +----------+--------------------------------+--------+-------------+ | MyDB | AO_60DB71_VERSION | 1 | 0 | | MyDB | AO_AEFED0_TEAM_TO_MEMBER | 1 | 0 | | MyDB | AO_4B00E6_STASH_SETTINGS | 1 | 0 | | MyDB | AO_2D3BEA_FOLIOCF | 1 | 0 | | MyDB | AO_AEFED0_TEAM_ROLE | 1 | 0 | | MyDB | AO_60DB71_DETAILVIEWFIELD | 1 | 0 | | MyDB | AO_60DB71_LEXORANK | 1 | 0 | | MyDB | AO_6714C7_REPORT_SCHEDULE | 1 | 0 | | MyDB | AO_E8B6CC_SYNC_AUDIT_LOG | 1 | 0 | | MyDB | cwd_application | 1 | 0 | | MyDB | clusternode | 1 | 0 | | MyDB | AO_86ED1B_GRACE_PERIOD | 1 | 0 | | MyDB | AO_60DB71_WORKINGDAYS | 1 | 0 | | MyDB | cwd_directory | 1 | 0 | | MyDB | AO_2D3BEA_BASELINE | 1 | 0 | | MyDB | fieldlayoutitem | 1 | 0 | | MyDB | JQUARTZ_BLOB_TRIGGERS | 1 | 0 | | MyDB | AO_013613_HD_SCHEME_MEMBER | 1 | 0 | | MyDB | AO_2D3BEA_ALLOCATION | 1 | 0 | | MyDB | AO_013613_WL_SCHEME | 1 | 0 | | MyDB | AO_7DEABF_EXEC_CLUSTER_MESSAGE | 1 | 0 | ....................................................................
如上截圖,執行 mysqldump 命令的時候,使用 show open tables where in_use 0 命令,你會看到 MyDB 里面的所有表的 In_use 的值都為 1,意味著是當執行 mysqldump 命令時,是一次性鎖定當前庫的所有表。而不是鎖定當前導出表。
In_use 說明
The number of table locks or lock requests there are for the table. For example, if one client acquires a lock for a table using LOCK TABLE t1 WRITE, In_use will be 1. If another client issues LOCK TABLE t1 WRITE while the table remains locked, the client will block waiting for the lock, but the lock request causes In_use to be 2. If the count is zero, the table is open but not currently being used. In_use is also increased by the HANDLER … OPEN statement and decreased by HANDLER … CLOSE.
關于 MySQLump 中 Lock-Tables 參數的作用是什么問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注丸趣 TV 行業資訊頻道了解更多相關知識。