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. 在关闭页面时自动清除Session cookie,页面缓存

    在默认情况下,session对象在关闭浏览器后并不是立刻被销毁,因此,为了考虑系统的安全性,在用户退出时,需要即刻清除session对象,防止他人盗用session对象中的信息. 清除session对 ...

  2. 使用Domain-Driven创建Hypermedia API

    在现实中我们会遇到各种各样的复杂场景,"There is not a right way" 用来描述API的设计方法再合适不过了,没有一种API设计方式可以应对所有的场景.区别于& ...

  3. 各个系统下ping IP+端口的方法

    前言 做开发的人员,可能都会遇到网络的一些问题.这时一般都需要测试指定的网络是否能正常访问.通常在windows系统下,在cmd里直接用命令ping指定的IP或者域名就可以快速的知道这个地址是否是可以 ...

  4. Perl基础速成

    本文是针对没有Perl基础,但想用perl一行式命令取代grep/awk/sed的人,用于速学Perl基础知识. Perl一行式系列文章:Perl一行式程序 perl的-e选项 perl命令的-e选项 ...

  5. 【转载】C#常用数据库Sqlserver通过SQL语句查询数据库以及表的大小

    在Sqlserver数据库中,一般我们查看数据库的大小可以通过查找到数据库文件来查看,但如果要查找数据表Table的大小的话,则不可通过此方法,在Sqlserver数据库中,提供了相应的SQL语句来查 ...

  6. 阿里云redis映射到阿里云服务器

    参考文档:https://help.aliyun.com/document_detail/43850.html?spm=a2c4g.11186623.2.3.7yg9VH ECS Windows 篇 ...

  7. oracle中rownum的使用

    rownum是系统的一个关键字,表示行号,是系统自动分配的,第一条符合要求的数据行号就是1,第二条符合要求的数据行号就是2. Rownum 不能直接使用 例:取前多少条数据: 取中间的一些数据: se ...

  8. python同步、互斥锁、死锁

    目录 同步 同步的概念 解决线程同时修改全局变量的方式 互斥锁 使用互斥锁完成2个线程对同一个全局变量各加9999999 次的操作 上锁解锁过程 总结 死锁 避免死锁 同步 同步的概念 同步就是协同步 ...

  9. 异常:android.os.NetworkOnMainThreadException

    场景: 安卓开发时在主线程访问网络解决: 将访问网络的代码使用Thread操作 Handler handler = new Handler(){ @Override public void handl ...

  10. C#中try catch finally的执行顺序

    1.首先明确一点,就是不管怎样,finally一定会执行,即使程序有异常,并且在catch中thorw 了 ,finally还是会被执行. 2.当try和catch中有return时,finally仍 ...