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

mysqldump 参数--lock-tables浅析的更多相关文章

  1. mysqldump: Got error: 1142: SELECT, LOCK TABLES command denied to user 'root'@'localhost' for table 'accounts' when using LOCK TABLES

    AutoMySQLBackup备份时,出现mysqldump: Got error: 1142: SELECT, LOCK TABLES command denied to user 'root'@' ...

  2. mysqldump: Got error: 1556: You can't use locks with log tables. when using LOCK TABLES

    mysqldump: Got error: 1556: You can't use locks with log tables. when using LOCK TABLES 我是把一些mysqldu ...

  3. mysqldump: Got error: 1449: The user specified as a definer ('user'@'%') does not exist when using LOCK TABLES

    报错:一个库用mysqldump -u -p --opt --force -e --max_allowed_packet= --net_buffer_length= --databases备份时报错如 ...

  4. mysqldump when doing LOCK TABLES问题

    今天打出表结构和数据遇到问题. mysqldump -udbuser -p dbname > dbname.sql 保存信息为: when doing LOCK TABLES 解决方法: mys ...

  5. mysqldump备份数据库时出现when using LOCK TABLES

    用mysqldump备份数据库时,如果出现when using LOCK TABLES,解决办法是加上 --skip-lock-tables 例如: 用mysqldump备份数据库时出现 29: Fi ...

  6. Centos下_MysqL5.7在使用mysqldump命令备份数据库报错:mysqldump: Got error: 1449: The user specified as a definer ('fk_system'@'localhost') does not exist when using LOCK TABLES

    在阿里云服务器增加一个shell脚本定时备份数据库脚本执行任务时,测试性的执行了备份命令,如下 [root@iZ2ze503xw2q1fftv5rhboZ mysql_bak]# /usr/local ...

  7. MySQL中lock tables和unlock tables浅析

    MySQL中lock tables和unlock tables浅析   在MySQL中提供了锁定表(lock tables)和解锁表(unlock tables)的语法功能,ORACLE与SQL Se ...

  8. 在给mysql数据库备份时,报错: mysqldump: Got error: 145: Table '.\shengdaxcom\pre_forum_thread' is marked as c rashed and should be repaired when using LOCK TABLES

    在给mysql数据库备份时,报错: mysqldump: Got error: 145: Table '.\shengdaxcom\pre_forum_thread' is marked as cra ...

  9. mysqldump: Got error: 1449: The user specified as a definer ('xxx'@'%') does not exist when using LOCK TABLES

    开发同学说在测试环境使用mysqldump导出数据的时候遇到以下错误: # mysqldump -uroot -p --all-databases --routines --events --trig ...

  10. Mysqldump参数大全

    Mysqldump参数大全(参数来源于mysql5.5.19源码)   参数 参数说明 --all-databases  , -A 导出全部数据库. mysqldump  -uroot -p --al ...

随机推荐

  1. 一个BAT老程序员的忠告!

      一.在中国,你千万不要因为学习技术就可以换来稳定的生活和高的薪水待遇,你更不要认为那些从事市场.运营的人,没有前途. 不清楚你是不是知道,咱们中国有相当大的一部分软件公司,他们的软件开发团队都小的 ...

  2. 小程序开发--移动端分辨率与rpx

    首先说一个很有意思的问题:一块720p的屏幕和1080p的屏幕那个大? 这个问题很有代表性,如果手机竖着放,720p=720px*1280px,而1080p=1080px*1920px;那么在宽度上, ...

  3. 阿里云CentOS安装配置Python3.7及pip3

    一.安装Python3.7 安装依赖包 yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqli ...

  4. 前端XSS相关整理

    前端安全方面,主要需要关注 XSS(跨站脚本攻击 Cross-site scripting) 和 CSRF(跨站请求伪造 Cross-site request forgery) 当然了,也不是说要忽略 ...

  5. 2017 ACM/ICPC Asia Regional Shenyang Online(部分题解)

    HDU 6197 array array array 题意 输入n和k,表示输入n个整数和可以擦除的次数k,如果至多擦除k次能是的数组中的序列是不上升或者是不下降序列,就是魔力数组,否则不是. 解题思 ...

  6. 【Go】获取用户真实的ip地址

    原文链接:https://blog.thinkeridea.com/201903/go/get_client_ip.html 用户请求到达提供服务的服务器中间有很多的环节,导致服务获取用户真实的 ip ...

  7. shell的命令替换和命令组合

    bash&shell系列文章:http://www.cnblogs.com/f-ck-need-u/p/7048359.html Linux中使用反引号"``"(在波浪线的 ...

  8. 分布式系统监视zabbix讲解五之web监控--技术流ken

    Web 监控 概况 你可以使用 Zabbix 检查几个网站可用性方面. 如果要使用 Web 检测功能,必须在 编译Zabbix 的时候加入 cURL(libcurl) 的支持. 要使用 Web 监控, ...

  9. VUE 组件通信总结

    1.prop 父组件传递给子组件,即通过VUE本身具有的Props属性来传递值 Child组件 <template> <span>{{message}}</span> ...

  10. 介绍一款文档神器:pandoc

    http://pandoc.org/ 因为工作需要,将一批markdown的文档转换成word文档,找来找去,这个pandoc真是神器 啊,推荐给大家 If you need to convert f ...