One command, which few people realize exists is SHOW OPEN TABLES – it allows you to examine what tables do you have open right now:

 mysql> show open tables from test;
+----------+-------+--------+-------------+
| Database | Table | In_use | Name_locked |
+----------+-------+--------+-------------+
| test | a | 3 | 0 |
+----------+-------+--------+-------------+
1 row in set (0.00 sec)

This command lists all non-temporary tables in the table-cache, showing each of them only once (even if table is opened more than ones)

In_use show how many threads are currently using this table, meaning have it locked or waiting on the table lock for this table to lock it.

Name_locked shows whenever the name for this table is locked. It is used for DROP or RENAME TABLE, so you would very rarely see this field to contain anything else than 0.

Besides just figuring out what tables are in the table_cache this command is rather helpful to understand if there is activity on the given table. Just run “FLUSH TABLES mytable” and examine open tables later – if you see this table in table cache again chances are it is being used.

Note however if you’re starting MySQL Command line client without “-A” option it opens all tables in the active database to allow tab completion which can screw results.

Another use for this command is pre-flush implementation (as part of your backup routine) – instead of running FLUSH TABLES on ALL tables one by one you can run SHOW OPEN TABLES and flush only open tables, when run it again and see how many tables are open and in use and if FLUSH TABLES WITH READ LOCK can be run or not.

Unfortunately this command does not really help to answer the very common question you may have during table lock troubleshooting – who is holding lock for this table ?

I would much rather see all entries in the table_cache used, not grouped by the table, with thread_id using the table set (0 if table is not in use), lock_type READ/WRITE/READ_LOCAL etc as well as whenever the thread is looking for lock right now.

It also deserves to be converted to INFORMATION_SCHEMA table – so it would be easily to operate it using SQL commands.

Another thing which would be handly is LRU position for the given table (so you can see what tables are candidates for replacement) and the timestamp when this table was locked (or lock wait started) – MySQL anyway initializes the timer so it would not be much overhead to store that time together in the table cache. This could allow to understand table locks much better.

转自:http://www.mysqlperformanceblog.com/2008/12/14/show-open-tables-what-is-in-your-table-cache/

SHOW OPEN TABLES – what is in your table cache的更多相关文章

  1. detecting locked tables mysql (locked by LOCK TABLE)

    detecting locked tables mysql (locked by LOCK TABLE) up vote15down votefavorite 7 I would like to kn ...

  2. 如何安全地关闭MySQL实例

    如何安全地关闭MySQL实例 转载自:http://imysql.com/2014/08/13/mysql-faq-howto-shutdown-mysqld-fulgraceful.shtml 本文 ...

  3. MySQL优化之——安全地关闭MySQL实例

    转载请注明出处:http://blog.csdn.net/l1028386804/article/details/46812371 关闭过程: 1.发起shutdown,发出  SIGTERM信号 2 ...

  4. 安全关闭MySQL

    想要安全关闭 mysqld 服务进程,建议按照下面的步骤来进行: 0.用具有SUPER.ALL等最高权限的账号连接MySQL,最好是用 unix socket 方式连接: 1.在5.0及以上版本,设置 ...

  5. MySQL/MariaDB数据库的服务器配置

    MySQL/MariaDB数据库的服务器配置 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MySQL中的系统数据库 1>.mysql数据库 是mysql的核心数据库,类 ...

  6. People Tools catalog tables.

    People Tools catalog tables. Projects PSPROJECTDEFN — Project header table PSPROJECTITEM — Definitio ...

  7. Table of Contents ---BCM

    Table of ContentsAbout This Document................................................................ ...

  8. zstu.2512. Moving Tables(贪心)

     Moving Tables Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 1182  Solved: 563 Description The famo ...

  9. DB2 for z: system catalog tables

    http://www.ibm.com/support/knowledgecenter/SSEPEK_10.0.0/com.ibm.db2z10.doc.sqlref/src/tpc/db2z_cata ...

随机推荐

  1. URAL 1306 Sequence Median(优先队列)

    题意:求一串数字里的中位数.内存为1M.每个数范围是0到2的31次方-1. 思路:很容易想到把数字全部读入,然后排序,但是会超内存.用计数排序但是数又太大.由于我们只需要第n/2.n/2+1大(n为偶 ...

  2. sidePagination: "server"和responseHandler: responseHandler

    bootstrapTable()中有两个属性 一个是sidePagination,表示服务器分页,responseHandler:responseHandler 表示回应操作的rows和total 两 ...

  3. c++高质量编程手册

    怡化主管强烈要求我读这本书.... 笔记尚未完成,持续更新呗.. 第1章 高质量软件开发之道 1.1 软件质量基本概念 1.1.1 如何理解软件的质量:功能性和非公能性 1.1.2 提高软件质量的基本 ...

  4. Git 的安装和创建版本库 。

    Git 的优点就不再多说了 .直接进入正题吧 . 安装Git 首先可以尝试输入 Git 看看有没有反映 . $ git The program 'git' is currently not insta ...

  5. Intent的简介以及属性详解

    一.Intent的介绍 Intent的中文意思是“意图,意向”,在Android中提供了Intent机制来协助应用间的交互与通讯,Intent负责对应用中一次操作的动作.动作涉及数据.附加数据进行描述 ...

  6. Unity3D ShaderLab 使用贴图对模型的高光进行遮罩

    Unity3D ShaderLab 使用贴图对模型的高光进行遮罩 前面研究了高光效果的实现,再说说现很多游戏用到的高光贴图技术,因为它可以让3D美工更容易控制最终的视觉效果. 这也就为我们提供了另外的 ...

  7. windows操作系统的快捷键

    编号:1015时间:2016年5月26日09:25:34功能:windows操作系统的快捷键URL:https://www.douban.com/group/topic/5937774/

  8. 【题解】【BST】【Leetcode】Validate Binary Search Tree

    Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as ...

  9. 【转】C++析构函数为什么要为虚函数

    注:本文内容来源于zhice163博文,感谢作者的整理. 1.为什么基类的析构函数是虚函数? 在实现多态时,当用基类操作派生类,在析构时防止只析构基类而不析构派生类的状况发生. 下面转自网络:源地址  ...

  10. 理解HMM

    hidden markov model markov model: 把一个总随机过程看成一系列状态的不断转移, 其特性主要使用转移概率来表示. HMM:认为模型的状态是不可观测的(hidden), 能 ...