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 基于面向对象的 轮播图2

    <script> // 函数不能重名, --> 子函数 // is defined function --> 函数名是否写错了 function AutoTab(id) { T ...

  2. C/C++ 字符串 null terminal

    在C/C++中,字符串以'\0'结尾是一种强制要求,或者说,只有满足这个要求的 字符数组才能被称为字符串.否则,你所做的所有操作结果都是未定义的! C标准库string.h中所有关于字符串的函数都有一 ...

  3. linux基础命令学习(三)Vim使用

    1. # vim 1.txt 命令模式: a i o A I O x X yy dd p G dw de h j k l f H M B a --- append 追加 在光标所在位置后追加一个字符 ...

  4. ecpilise引入Maven项目目录不正常,无JRE,无Maven Dependencies

    原因是我的eclipse默认open perspective是java ee,改成java就恢复正常了.

  5. mysql的ERROR:1042

    在虚拟机上测试数据库备份功能,需要连接外部机器上的mysql,pdo总是报超时错误! 起初认为是用的mysql账号的域不匹配!后来发现不是因为这个! 在终端中用mysql命令尝试连接,发现返回的错误是 ...

  6. 联合与枚举 、 高级指针 、 C语言标准库(一)

    1 输入一个整数,求春夏秋冬 1.1 问题 在实际应用中,有的变量只有几种可能取值.如人的性别只有两种可能取值,星期只有七种可能取值.在 C 语言中对这样取值比较特殊的变量可以定义为枚举类型.所谓枚举 ...

  7. C++学习笔记6:多文件编程

    1.添加文件到工程中: 2.函数调用时需要前向声明;以下为实例: //add.cpp int add(int x, int y) { return (x + y); } //main.cpp #inc ...

  8. 传智springMVC笔记

    springmvc 第一天 springmvc的基础知识 课程安排: 第一天:springmvc的基础知识 什么是springmvc? springmvc框架原理(掌握) 前端控制器.处理器映射器.处 ...

  9. 帝国cms相关调用

    Loop用法:[!--temp.header--] [e:loop={6,6,0,1}] <!--标题连接/标题--> <a href="<?=$bqsr[title ...

  10. OpenFlow Switch学习笔记(六)——Instructions和Actions

    本文主要重点讨论OpenFlow Switch规范的指令集,它们深刻影响着数据包在Switch中的处理行为,下面开始从以下几个部分谈起. 1.Instructions 每一个Flow Entry里都包 ...