A better SHOW TABLE STATUS

时间:2023-01-27 14:22:55

From command line we have the entire MySQL server on hands (if we have privileges too of course) but we don’t have a overall overview, at this point the show table status command is every useful, or not?.

This is what we get when run show table status in a standard 80×25 terminal screen:

A better SHOW TABLE STATUS

We can maximize the terminal window and decrease font size, but not all the time we need that lots of info. Some time ago I develop a stored procedure to get a global overview including functions and stored procedures. The result is pretty comprehensible:

call tools.sp_status(database());
+----------------------------+--------+-------+---------+-----------------+
| Table Name | Engine | Rows | Size | Collation |
+----------------------------+--------+-------+---------+-----------------+
| actor | InnoDB | 200 | 0.03 Mb | utf8_general_ci |
| actor_info | [VIEW] | - | - | - |
| address | InnoDB | 589 | 0.09 Mb | utf8_general_ci |
| category | InnoDB | 16 | 0.02 Mb | utf8_general_ci |
| city | InnoDB | 427 | 0.06 Mb | utf8_general_ci |
| country | InnoDB | 109 | 0.02 Mb | utf8_general_ci |
| customer | InnoDB | 541 | 0.12 Mb | utf8_general_ci |
| customer_list | [VIEW] | - | - | - |
| film | InnoDB | 1131 | 0.27 Mb | utf8_general_ci |
| film_actor | InnoDB | 5143 | 0.27 Mb | utf8_general_ci |
| film_category | InnoDB | 316 | 0.08 Mb | utf8_general_ci |
| film_list | [VIEW] | - | - | - |
| film_text | MyISAM | 1000 | 0.31 Mb | utf8_general_ci |
| inventory | InnoDB | 4673 | 0.36 Mb | utf8_general_ci |
| language | InnoDB | 6 | 0.02 Mb | utf8_general_ci |
| nicer_but_slower_film_list | [VIEW] | - | - | - |
| payment | InnoDB | 15422 | 2.12 Mb | utf8_general_ci |
| rental | InnoDB | 15609 | 2.72 Mb | utf8_general_ci |
| sales_by_film_category | [VIEW] | - | - | - |
| sales_by_store | [VIEW] | - | - | - |
| staff | InnoDB | 1 | 0.09 Mb | utf8_general_ci |
| staff_list | [VIEW] | - | - | - |
| store | InnoDB | 2 | 0.05 Mb | utf8_general_ci |
+----------------------------+--------+-------+---------+-----------------+
23 rows in set (0.04 sec) +----------------------------+-----------+---------------------+
| Routine Name | Type | Comment |
+----------------------------+-----------+---------------------+
| get_customer_balance | FUNCTION | |
| inventory_held_by_customer | FUNCTION | |
| inventory_in_stock | FUNCTION | |
| film_in_stock | PROCEDURE | |
| film_not_in_stock | PROCEDURE | |
| rewards_report | PROCEDURE | |
| customer_create_date | TRIGGER | On INSERT: customer |
| del_film | TRIGGER | On DELETE: film |
| ins_film | TRIGGER | On INSERT: film |
| payment_date | TRIGGER | On INSERT: payment |
| rental_date | TRIGGER | On INSERT: rental |
| upd_film | TRIGGER | On UPDATE: film |
+----------------------------+-----------+---------------------+
12 rows in set (0.04 sec) Query OK, 0 rows affected (0.04 sec)

There is the procedure source code:

DELIMITER $$
DROP PROCEDURE IF EXISTS `tools`.`sp_status` $$
CREATE PROCEDURE `tools`.`sp_status`(dbname VARCHAR(50))
BEGIN
-- Obtaining tables and views
(
SELECT
TABLE_NAME AS `Table Name`,
ENGINE AS `Engine`,
TABLE_ROWS AS `Rows`,
CONCAT(
(FORMAT((DATA_LENGTH + INDEX_LENGTH) / POWER(1024,2),2))
, ' Mb')
AS `Size`,
TABLE_COLLATION AS `Collation`
FROM information_schema.TABLES
WHERE TABLES.TABLE_SCHEMA = dbname
AND TABLES.TABLE_TYPE = 'BASE TABLE'
)
UNION
(
SELECT
TABLE_NAME AS `Table Name`,
'[VIEW]' AS `Engine`,
'-' AS `Rows`,
'-' `Size`,
'-' AS `Collation`
FROM information_schema.TABLES
WHERE TABLES.TABLE_SCHEMA = dbname
AND TABLES.TABLE_TYPE = 'VIEW'
)
ORDER BY 1;
-- Obtaining functions, procedures and triggers
(
SELECT ROUTINE_NAME AS `Routine Name`,
ROUTINE_TYPE AS `Type`,
'' AS `Comment`
FROM information_schema.ROUTINES
WHERE ROUTINE_SCHEMA = dbname
ORDER BY ROUTINES.ROUTINE_TYPE, ROUTINES.ROUTINE_NAME
)
UNION
(
SELECT TRIGGER_NAME,'TRIGGER' AS `Type`,
concat('On ',EVENT_MANIPULATION,': ',EVENT_OBJECT_TABLE) AS `Comment`
FROM information_schema.TRIGGERS
WHERE EVENT_OBJECT_SCHEMA = dbname
)
ORDER BY 2,1;
END$$
DELIMITER ;

To use in your place you must call as:

mysql> call tools.sp_status(database());

Note the stored procedure has created in tools database (you can use another db), the goal of this is to call that useful procedure from any database, and it receives the name of database as parameter because is not possible obtain the current database from inside of stored procedure.

参考:

http://en.latindevelopers.com/ivancp/2012/a-better-show-table-status/

A better SHOW TABLE STATUS的更多相关文章

  1. mysqldump: Couldn't execute 'show table status '解决方法

    执行:[root@host2 lamp]# mysqldump -F -R -E --master-data=2   -p -A --single-transaction 在控制台端出现 mysqld ...

  2. mysql学习之-show table status(获取表的信息)参数说明

    --获取表的信息mysql> show table status like 'columns_priv'\G;*************************** 1. row ******* ...

  3. show table status

    SHOW TABLE STATUS works likes SHOW TABLES, but provides a lot of information about each non-TEMPORAR ...

  4. mysql命令学习笔记(1):show table status like 'user';显示表的相关信息

    show table status like 'user';显示表的相关信息 +------------+--------+---------+------------+------+-------- ...

  5. mysql中使用show table status 查看表信息

    本文导读:在使用mysql数据库时,经常需要对mysql进行维护,查询每个库.每个表的具体使用情况,Mysql数据库可以通过执行SHOW TABLE STATUS命令来获取每个数据表的信息. 一.使用 ...

  6. mysql中使用show table status 查看表信息

    学习标签: mysql 本文导读:在使用mysql数据库时,经常需要对mysql进行维护,查询每个库.每个表的具体使用情况,Mysql数据库可以通过执行SHOW TABLE STATUS命令来获取每个 ...

  7. mysql table status

    SHOW TABLE STATUS 能获得表的信息 可以SHOW TABLE STATUS where name='表名'

  8. mysql中 show table status 获取表信息

    用法 mysql>show table status; mysql>show table status like 'esf_seller_history'\G; mysql>show ...

  9. MySQL通过SHOW TABLE STATUS查看库中所有表的具体信息

    有时候我们想看下指定库下所有表的使用情况,比如,查询表的Table大小,什么时候创建的,数据最近被更新的时间(即最近一笔insert/update/delete的时间).这些信息对我们进行库表维护很有 ...

随机推荐

  1. hdu 1159 Common Subsequence(LCS最长公共子序列)

    Common Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  2. Java中获取路径的方法_自我分析

    就目前的我来说最常用的两种获取路径的方法是  class.getRecource(filename) 和 class.getclassloader.getRecource(filename) 这两者的 ...

  3. XML编辑工具

    [标题]XML编辑工具 [开发环境]Qt 5.2.0 [概要设计]使用QT的视图/模型结构.treeview控件以树形结构显示所要操作的XML文件,并实现xml的相关操作 [详细设计] 主要包含 no ...

  4. 使用chan的时候选择对象还是指针

    使用chan的时候选择对象还是指针 今天在写代码的时候遇到一个问题,在创建一个通道的时候,不确定创建的通道是使用chan A还是chan *A. 思考了一下,觉得这个应该和函数一样是一个值传递还是参数 ...

  5. HTTP响应 状态码描述

  6. CSRF与SSRF区别

    CSRF 攻击者盗用了你的身份,以你的名义发送恶意请求.CSRF能够做的事情包括:以你的名义发送邮件,发消息,盗用你的账号,甚至于购买商品,虚拟货币转账... 发生条件: 1.登录受信任网站A,并在本 ...

  7. @transactional注解下失效

    这几天在项目里面发现我使用@Transactional注解事务之后,抛了异常居然不回滚.后来终于找到了原因. 如果你也出现了这种情况,可以从下面开始排查. 一.特性 先来了解一下@Transactio ...

  8. Altera FPGA SoC搭建步骤

    Altera SoC 官方搭建指南: https://rocketboards.org/foswiki/Documentation/EmbeddedLinuxBeginnerSGuide 官方文档中除 ...

  9. Windows如何安装pip

    下载这个文件:  https://bootstrap.pypa.io/get-pip.py 然后到下载目录执行Python命令:   (管理员权限执行) python get-pip.py

  10. C#中怎么判断一个数组中是否存在某个数组值

    (1) 第一种方法: ,,}; ); // 这里的1就是你要查找的值 ) // 不存在 else // 存在 (2) 第二种方法: string[] strArr = {"a",& ...