A better SHOW TABLE STATUS
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的更多相关文章
- mysqldump: Couldn't execute 'show table status '解决方法
执行:[root@host2 lamp]# mysqldump -F -R -E --master-data=2 -p -A --single-transaction 在控制台端出现 mysqld ...
- mysql学习之-show table status(获取表的信息)参数说明
--获取表的信息mysql> show table status like 'columns_priv'\G;*************************** 1. row ******* ...
- show table status
SHOW TABLE STATUS works likes SHOW TABLES, but provides a lot of information about each non-TEMPORAR ...
- mysql命令学习笔记(1):show table status like 'user';显示表的相关信息
show table status like 'user';显示表的相关信息 +------------+--------+---------+------------+------+-------- ...
- mysql中使用show table status 查看表信息
本文导读:在使用mysql数据库时,经常需要对mysql进行维护,查询每个库.每个表的具体使用情况,Mysql数据库可以通过执行SHOW TABLE STATUS命令来获取每个数据表的信息. 一.使用 ...
- mysql中使用show table status 查看表信息
学习标签: mysql 本文导读:在使用mysql数据库时,经常需要对mysql进行维护,查询每个库.每个表的具体使用情况,Mysql数据库可以通过执行SHOW TABLE STATUS命令来获取每个 ...
- mysql table status
SHOW TABLE STATUS 能获得表的信息 可以SHOW TABLE STATUS where name='表名'
- mysql中 show table status 获取表信息
用法 mysql>show table status; mysql>show table status like 'esf_seller_history'\G; mysql>show ...
- MySQL通过SHOW TABLE STATUS查看库中所有表的具体信息
有时候我们想看下指定库下所有表的使用情况,比如,查询表的Table大小,什么时候创建的,数据最近被更新的时间(即最近一笔insert/update/delete的时间).这些信息对我们进行库表维护很有 ...
随机推荐
- Be a person
做人不能太实诚 尤其是干我们这行的 多久时间能做完 你自己心里要有个估算 然后把时间再往后延 别他妈给自己找罪受
- AppCan相关网站
AppCan文档中心: http://doc.appcan.cn/#!/guide/handbook AppCan官网: http://www.appcan.cn/index.html
- 永不消逝的电波(三):低功耗蓝牙(BLE)入门之如何调戏别人的小米手环
0×00 前言 蓝牙(Bluetooth),一种无线技术标准,用来让固定与移动设备,在短距离间交换数据,以形成个人局域网(PAN).其使用短波特高频(UHF)无线电波,经由2.4至2.485 GHz的 ...
- S50非接触式IC卡性能简介(M1)
一.主要指标 分为16个扇区,每个扇区为4块,每块16个字节,以块为存取单位: 每个扇区有独立的一组密码及访问控制: 每张卡有唯一序列号,为32位: 具有防冲突机制,支持多卡操作: 无电源,自带天线, ...
- Java三大主流开源工作流引擎技术分析
首先,这个评论是我从网上,书中,搜索和整理出来的,也许有技术点上的错误点,也许理解没那么深入.但是我是秉着学习的态度加以评论,学习,希望对大家有用,进入正题! 三大主流工作流引擎:Shark,oswo ...
- Ubuntu 升级VisualBox后无法启动 Kernel driver not installed (rc=-1908)
VisualBox之所以在Linux上比传统的VMware快得多,关键一点就是它和Linux内核的结合比较紧密,这也是开源的优点. 不过Linux内核更新很频繁,每次更新内核后启动VirtualBox ...
- How to set up a basic working Appium test environment
Appium is a test framework targeting devices; although it is very handy and powerful, it is not so s ...
- Git使用详细教程
参考网址: http://www.admin10000.com/document/5374.html http://blog.sina.com.cn/s/blog_4f3b79d0010166ab.h ...
- 12、C#基础整理(结构体)
结构体 1.概念: 结构体是写在main函数外的数据结构,由不同类型的数据组合成一个整体,这些组合在一个整体中的数据是互相联系的 2.声明方式: struct 结构体名 { 成员变量(由类型名+成员名 ...
- supervisor很赞!
最近,公司进行了新的架构设计,原来一个区服一组进程,变成了对外只有一台服,后面N组多进程进行服务的模式.于是,管理进程就变成了一个头痛的问题.原来是在写代码的目录里放置各种脚本解决的,关闭脚本,开启脚 ...