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的时间).这些信息对我们进行库表维护很有 ...
随机推荐
- Ubuntu 14.10 下设置时间同步
在启动HBase机群的时候,发现了一个错误,因为机群时间不同步导致,所以要同步集群时间. Linux的时间分为System Clock(系统时间)和Real Time Clock (硬件时间,简称RT ...
- android-volley-at-a-glance
http://liubin.org/2013/05/27/android-volley-at-a-glance/ http://www.androidhive.info/2014/05/android ...
- 并非然并卵的z-index
最近做一些东西的时候总觉得加上z-index和不加对于最终的显示结果并没有什么区别,开始以为一张图片把z-inde的值调小一点儿,就可以当做背景图片一样使用,跟background是一样的,在试过几次 ...
- 结构体,内存,指针例题.DOC
2015.1.30 递归函数:1.自身调用自己:2.要有结束条件!typedef 后面加分号:一般后面的重定义名加_,例如:typedef unsigned long int uint_16;结构体成 ...
- POJ 3278 经典BFS
进一步了解了bfs; 题意:给你n,然后用+,-,*三种运算使n变成k; 漏洞:在算出新的数字之后,一定要判边界,否则RE,而且在每一步后面都得加判断是否等于K,如果是即刻退出,否则WA,判这个的时候 ...
- 20145210 《Java程序设计》第一周学习总结
教材学习内容总结 第一章: 1.Java三大平台,JavaSE的四个组成部分 Java根据应用领域的不同,区分为Java SE.Java EE.Java ME三大平台. 各应用平台的基础:Java S ...
- arcgis显示其他国家语言
接手一个韩国的项目,需要在arcmap中配置一个韩国地图并发布到arcserver中进行切图,给的韩国地图的shapefile文件中属性字段都是韩文的,在中文的系统中,arcMap中显示的韩文都是乱码 ...
- Application,Session,Cookie,ViewState和Cache区别
在ASP.NET中,有很多种保存信息的内置对象,如:Application,Session,Cookie,ViewState和Cache等.下面分别介绍它们的用法和区别. 方法 信息量大小 作用域和保 ...
- MVC 构造新Model实现内容搜索
当前在使用MVC开发一个网站,习惯了使用ASP.NET中控件,转到MVC之后突然对于页面和后台代码的传值感觉无从下手.花了点时间在网上看了写帖子后,想到了一个方法,重新构造一个新Model, 然后利用 ...
- jquery ui tab标签
<!DOCTYPE html> <html> <head> <title>tab</title> <style type=" ...