MySQLump 参数--Lock-Tables浅析

本文转载自微信公众号「DBA闲思杂想录」,参数作者潇湘隐者 。浅析转载本文请联系DBA闲思杂想录公众号。参数     

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 >0; +----------+--------------------------------+--------+-------------+ | 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.

参考资料:

https://dev.mysql.com/doc/refman/5.7/en/show-open-tables.html

https://oracle-base.com/articles/mysql/mysql-identify-locked-tables

IT科技
上一篇:蓝牙错误(排除蓝牙连接问题的常见解决方法)
下一篇:华硕S400E3317CA——性能卓越的笔记本电脑(华硕S400E3317CA引领移动办公新潮流)