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:

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. JS原生回到顶部效果

    // 回到顶部 onload = function () { var oBtnTop = document.getElementById('toTop'); var timer = null; oBt ...

  2. C# 跨线程操作控件(简洁)

                                              C# 跨线程操作控件 .net 原则上禁止跨线程访问控件,因为这样可能造成错误的发生.解决此问题的方法有两个: 第一 ...

  3. Python 安全类目推荐 (持续更新)

    推荐学习书目 › Learn Python the Hard Way › Python 学习手册 › Python Cookbook › Python 基础教程 Python Sites › PyPI ...

  4. LeetCode---Word Break 2

    Given a string s and a dictionary of wordsdict, add spaces in s to construct a sentence where each w ...

  5. 初始React Native

    1.何是React Native: React-Native是:Facebook 在2015年初React.js技术研讨大会上公布的一个开源项目.支持用开源的JavaScript库React.js来开 ...

  6. HDU5437 Alisha’s Party 优先队列

    点击打开链接 可能出现的问题: 1.当门外人数不足p人时没有判断队列非空,导致RE. 2.在m次开门之后最后进来到一批人没有入队. 3.给定的开门时间可能是打乱的,需要进行排序. #include&l ...

  7. Charlie's Change_完全背包&&路径记录

    Description Charlie is a driver of Advanced Cargo Movement, Ltd. Charlie drives a lot and so he ofte ...

  8. FATE_完全背包

    ps:原来用新浪,可是代码的排版不是很好,所以用博客园啦,先容许我把从八月份开始的代码搬过来,从这里重新出发,希望这里可以一直见证我的成长. Time Limit: 2000/1000 MS (Jav ...

  9. Day03_JAVA语言基础第三天

    1.位运算符 1.面试题(掌握) ^:一个数据对同一个数据^两次,结果还是数据本身 举例:a ^ b ^ b = a  2.注意 知道结论,面试题,以后就完全不用看了 2.逻辑运算符(掌握)     ...

  10. 图像金字塔及其在 OpenCV 中的应用范例(上)

    前言 图像金字塔是计算机图形学中非常重要的一个概念. 本文将详细介绍这个概念,以及它的实现与应用. 图像金字塔的定义 图像金字塔是一组图像的集合,集合中的所有图像都是通过对某一图像连续降采样得到的一组 ...