mysqldump 参数--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 >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浅析的更多相关文章
- 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'@' ...
- 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 ...
- 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备份时报错如 ...
- mysqldump when doing LOCK TABLES问题
今天打出表结构和数据遇到问题. mysqldump -udbuser -p dbname > dbname.sql 保存信息为: when doing LOCK TABLES 解决方法: mys ...
- mysqldump备份数据库时出现when using LOCK TABLES
用mysqldump备份数据库时,如果出现when using LOCK TABLES,解决办法是加上 --skip-lock-tables 例如: 用mysqldump备份数据库时出现 29: Fi ...
- 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 ...
- MySQL中lock tables和unlock tables浅析
MySQL中lock tables和unlock tables浅析 在MySQL中提供了锁定表(lock tables)和解锁表(unlock tables)的语法功能,ORACLE与SQL Se ...
- 在给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 ...
- 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 ...
- Mysqldump参数大全
Mysqldump参数大全(参数来源于mysql5.5.19源码) 参数 参数说明 --all-databases , -A 导出全部数据库. mysqldump -uroot -p --al ...
随机推荐
- ELK实践(一):基础入门
虽然用了ELK很久了,但一直苦于没有自己尝试搭建过,所以想抽时间尝试尝试.原本打算按照教程 <ELK集中式日志平台之二 - 部署>(作者:樊浩柏科学院) 进行测试的,没想到一路出了很多坑, ...
- 第一个NHibernateDemo
什么是Nhibernate,Nhibernate是一个面向.Net环境的对 象/关系数据库映射工具.(ORM) 1.搭建项目基本框架: (1)创建MVC项目,命名为NHShop.Web. (2)依次分 ...
- crontab的使用笔记
1 crond简介crond是linux下用来周期性的执行某种任务或等待处理某些事件的一个守护进程,与windows下的计划任务类似,当安装完成操作系统后,默认会安装此服务工具,并且会自动启动cron ...
- for循环中let与var的区别,块级作用域如何产生与迭代中变量i如何记忆上一步的猜想
我在前一篇讨论let与var区别的博客中,顺带一笔带过了let与var在for循环中的不同表现,虽然解释了是块级作用域的影响,但具体是怎么去影响的呢,我尝试的去理解了下,这篇博客主要从for循环步骤拆 ...
- zend studio快捷键
某些快捷键会失效,多尝试就好.快捷键就是一种减轻工作量的方式,或者说展示码农码代码的熟练度,重要的还在于对一个问题的看法和角度,说的具体些就是算法和数据结构,不看会后悔,不学设计模式也会吃亏. 应用场 ...
- 数据库部分(MySql)_3
表设计之关联关系 一对一:有两张表A和B,A表中有一条数据对应B表中的一条数据称为一对一: 应用场景:用户表和用户扩展表,商品表和商品信息扩展表: 如何建立关系:在从表中添加一个外键字段指向主表的主键 ...
- 《Office 365开发入门指南》上市说明和读者服务
写在最开始的话 拙作<Office 365开发入门指南>上周开始已经正式在各大书店.在线商城上市,欢迎对Office 365的开发.生态感兴趣的开发者.项目经理.产品经理参考本书,全面了解 ...
- 48.Linux-普通U盘以及多分区U盘自动挂载
在上章学习33.Linux-实现U盘自动挂载(详解)后,只是讲解了普通U盘挂载,并没有涉及到多分区U盘,接下来本章来继续学习 1.多分区U盘和普通U盘区别 1)U盘插上只会创建一个/dev/sda文件 ...
- 45.work_struct和delayed_work的工作队列使用
介绍 在中断处理中,经常用到工作队列,这样便能缩短中断处理时的时间 中断中通过调用schedule_work(work)来通知内核线程,然后中断结束后,再去继续执行work对应的func函数 示例 当 ...
- HTML设为首页/加入收藏代码
(特别注意:要把'这个符号换成无任何输入法状态中输入的'这个符号,否则程序无法运行) 1.文字型: <a onclick="this.style.behavior='url ...