{"id":26,"date":"2012-02-25T08:00:15","date_gmt":"2012-02-25T08:00:15","guid":{"rendered":"http:\/\/en.latindevelopers.com\/ivancp\/?p=26"},"modified":"2012-02-25T13:16:24","modified_gmt":"2012-02-25T13:16:24","slug":"a-better-show-table-status","status":"publish","type":"post","link":"http:\/\/en.latindevelopers.com\/ivancp\/2012\/a-better-show-table-status\/","title":{"rendered":"A better SHOW TABLE STATUS"},"content":{"rendered":"<p>From command line we have the entire MySQL server on hands (if we have privileges too of course) but we don&#8217;t have a overall overview, at this point the <code>show table status<\/code> command is every useful, or not?.<\/p>\n<p>This is what we get when run <code>show table status<\/code> in a standard 80&#215;25 terminal screen:<\/p>\n<p style=\"text-align: left;\"><a href=\"http:\/\/en.latindevelopers.com\/ivancp\/wp-content\/uploads\/mysql-show-table-status.png\"><img loading=\"lazy\" class=\"aligncenter size-Big-Preview wp-image-32\" title=\"mysql-show-table-status\" src=\"http:\/\/en.latindevelopers.com\/ivancp\/wp-content\/uploads\/mysql-show-table-status-450x300.png\" alt=\"\" width=\"450\" height=\"300\" srcset=\"http:\/\/en.latindevelopers.com\/ivancp\/wp-content\/uploads\/mysql-show-table-status-450x300.png 450w, http:\/\/en.latindevelopers.com\/ivancp\/wp-content\/uploads\/mysql-show-table-status-300x199.png 300w, http:\/\/en.latindevelopers.com\/ivancp\/wp-content\/uploads\/mysql-show-table-status.png 737w\" sizes=\"(max-width: 450px) 100vw, 450px\" \/><\/a><\/p>\n<p>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:<\/p>\n<pre lang=\"text\">call tools.sp_status(database());\r\n+----------------------------+--------+-------+---------+-----------------+\r\n| Table Name                 | Engine | Rows  | Size    | Collation       |\r\n+----------------------------+--------+-------+---------+-----------------+\r\n| actor                      | InnoDB | 200   | 0.03 Mb | utf8_general_ci |\r\n| actor_info                 | [VIEW] | -     | -       | -               |\r\n| address                    | InnoDB | 589   | 0.09 Mb | utf8_general_ci |\r\n| category                   | InnoDB | 16    | 0.02 Mb | utf8_general_ci |\r\n| city                       | InnoDB | 427   | 0.06 Mb | utf8_general_ci |\r\n| country                    | InnoDB | 109   | 0.02 Mb | utf8_general_ci |\r\n| customer                   | InnoDB | 541   | 0.12 Mb | utf8_general_ci |\r\n| customer_list              | [VIEW] | -     | -       | -               |\r\n| film                       | InnoDB | 1131  | 0.27 Mb | utf8_general_ci |\r\n| film_actor                 | InnoDB | 5143  | 0.27 Mb | utf8_general_ci |\r\n| film_category              | InnoDB | 316   | 0.08 Mb | utf8_general_ci |\r\n| film_list                  | [VIEW] | -     | -       | -               |\r\n| film_text                  | MyISAM | 1000  | 0.31 Mb | utf8_general_ci |\r\n| inventory                  | InnoDB | 4673  | 0.36 Mb | utf8_general_ci |\r\n| language                   | InnoDB | 6     | 0.02 Mb | utf8_general_ci |\r\n| nicer_but_slower_film_list | [VIEW] | -     | -       | -               |\r\n| payment                    | InnoDB | 15422 | 2.12 Mb | utf8_general_ci |\r\n| rental                     | InnoDB | 15609 | 2.72 Mb | utf8_general_ci |\r\n| sales_by_film_category     | [VIEW] | -     | -       | -               |\r\n| sales_by_store             | [VIEW] | -     | -       | -               |\r\n| staff                      | InnoDB | 1     | 0.09 Mb | utf8_general_ci |\r\n| staff_list                 | [VIEW] | -     | -       | -               |\r\n| store                      | InnoDB | 2     | 0.05 Mb | utf8_general_ci |\r\n+----------------------------+--------+-------+---------+-----------------+\r\n23 rows in set (0.04 sec)\r\n\r\n+----------------------------+-----------+---------------------+\r\n| Routine Name               | Type      | Comment             |\r\n+----------------------------+-----------+---------------------+\r\n| get_customer_balance       | FUNCTION  |                     |\r\n| inventory_held_by_customer | FUNCTION  |                     |\r\n| inventory_in_stock         | FUNCTION  |                     |\r\n| film_in_stock              | PROCEDURE |                     |\r\n| film_not_in_stock          | PROCEDURE |                     |\r\n| rewards_report             | PROCEDURE |                     |\r\n| customer_create_date       | TRIGGER   | On INSERT: customer |\r\n| del_film                   | TRIGGER   | On DELETE: film     |\r\n| ins_film                   | TRIGGER   | On INSERT: film     |\r\n| payment_date               | TRIGGER   | On INSERT: payment  |\r\n| rental_date                | TRIGGER   | On INSERT: rental   |\r\n| upd_film                   | TRIGGER   | On UPDATE: film     |\r\n+----------------------------+-----------+---------------------+\r\n12 rows in set (0.04 sec)\r\n\r\nQuery OK, 0 rows affected (0.04 sec)<\/pre>\n<p style=\"text-align: left;\">There is the procedure source code:<\/p>\n<p style=\"text-align: left;\">\n<pre lang=\"sql\">DELIMITER $$\r\nDROP PROCEDURE IF EXISTS `tools`.`sp_status` $$\r\nCREATE PROCEDURE `tools`.`sp_status`(dbname varchar(50))\r\nBEGIN \r\n-- Obtaining tables and views\r\n(\r\n    SELECT \r\n     TABLE_NAME as `Table Name`, \r\n     ENGINE as `Engine`,\r\n     TABLE_ROWS as `Rows`,\r\n     CONCAT(\r\n        (FORMAT((DATA_LENGTH + INDEX_LENGTH) \/ POWER(1024,2),2))\r\n        , ' Mb')\r\n       as `Size`,\r\n     TABLE_COLLATION as `Collation`\r\n    FROM information_schema.TABLES\r\n    WHERE TABLES.TABLE_SCHEMA = dbname\r\n          AND TABLES.TABLE_TYPE = 'BASE TABLE'\r\n)\r\nUNION\r\n(\r\n    SELECT \r\n     TABLE_NAME as `Table Name`, \r\n     '[VIEW]' as `Engine`,\r\n     '-' as `Rows`,\r\n     '-' `Size`,\r\n     '-' as `Collation`\r\n    FROM information_schema.TABLES\r\n    WHERE TABLES.TABLE_SCHEMA = dbname \r\n          AND TABLES.TABLE_TYPE = 'VIEW'\r\n)\r\nORDER BY 1;\r\n-- Obtaining functions, procedures and triggers\r\n(\r\n    SELECT ROUTINE_NAME as `Routine Name`, \r\n     ROUTINE_TYPE as `Type`,\r\n     '' as `Comment`\r\n    FROM information_schema.ROUTINES\r\n    WHERE ROUTINE_SCHEMA = dbname\r\n    ORDER BY ROUTINES.ROUTINE_TYPE, ROUTINES.ROUTINE_NAME\r\n)\r\nUNION\r\n(\r\n    SELECT TRIGGER_NAME,'TRIGGER' as `Type`, \r\n    concat('On ',EVENT_MANIPULATION,': ',EVENT_OBJECT_TABLE) as `Comment`\r\n    FROM information_schema.TRIGGERS\r\n    WHERE EVENT_OBJECT_SCHEMA = dbname\r\n)\r\nORDER BY 2,1;\r\nEND$$\r\nDELIMITER ;<\/pre>\n<p>To use in your place you must call as:<\/p>\n<pre>mysql&gt; call tools.sp_status(database());<\/pre>\n<p>Note the stored procedure has created in <code>tools<\/code> 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 <strong>not possible<\/strong> obtain the current database from inside of stored procedure.<\/p>\n<p>I published that code on\u00a0 <a href=\"http:\/\/forge.mysql.com\/tools\/tool.php?id=309\" target=\"_blank\">MySQL custom show table status<\/a> entry at forge.mysql.com.<\/p>\n<p>Any ideas to improving the source code to make it more useful?<\/p>\n<p>&nbsp;<\/p>\n<div id=\"_mcePaste\" class=\"mcePaste\" style=\"position: absolute; left: -10000px; top: 980px; width: 1px; height: 1px; overflow: hidden;\">\n<pre>`<\/pre>\n<\/div>\n<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-official sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"http:\/\/en.latindevelopers.com\/ivancp\/2012\/a-better-show-table-status\/\" data-text=\"A better SHOW TABLE STATUS\"  >Tweet<\/a><\/li><li class=\"share-facebook\"><div class=\"fb-share-button\" data-href=\"http:\/\/en.latindevelopers.com\/ivancp\/2012\/a-better-show-table-status\/\" data-layout=\"button_count\"><\/div><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>From command line we have the entire MySQL server on hands (if we have privileges too of course) but we don&#8217;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&#215;25 terminal screen: We [&hellip;]<\/p>\n<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-official sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"http:\/\/en.latindevelopers.com\/ivancp\/2012\/a-better-show-table-status\/\" data-text=\"A better SHOW TABLE STATUS\"  >Tweet<\/a><\/li><li class=\"share-facebook\"><div class=\"fb-share-button\" data-href=\"http:\/\/en.latindevelopers.com\/ivancp\/2012\/a-better-show-table-status\/\" data-layout=\"button_count\"><\/div><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div>","protected":false},"author":1,"featured_media":21,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[4],"tags":[5,6],"jetpack_featured_media_url":"http:\/\/en.latindevelopers.com\/ivancp\/wp-content\/uploads\/2012\/02\/logo-mysql-170x115.png","jetpack_shortlink":"https:\/\/wp.me\/p2f09V-q","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/en.latindevelopers.com\/ivancp\/wp-json\/wp\/v2\/posts\/26"}],"collection":[{"href":"http:\/\/en.latindevelopers.com\/ivancp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/en.latindevelopers.com\/ivancp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/en.latindevelopers.com\/ivancp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/en.latindevelopers.com\/ivancp\/wp-json\/wp\/v2\/comments?post=26"}],"version-history":[{"count":7,"href":"http:\/\/en.latindevelopers.com\/ivancp\/wp-json\/wp\/v2\/posts\/26\/revisions"}],"predecessor-version":[{"id":31,"href":"http:\/\/en.latindevelopers.com\/ivancp\/wp-json\/wp\/v2\/posts\/26\/revisions\/31"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/en.latindevelopers.com\/ivancp\/wp-json\/wp\/v2\/media\/21"}],"wp:attachment":[{"href":"http:\/\/en.latindevelopers.com\/ivancp\/wp-json\/wp\/v2\/media?parent=26"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/en.latindevelopers.com\/ivancp\/wp-json\/wp\/v2\/categories?post=26"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/en.latindevelopers.com\/ivancp\/wp-json\/wp\/v2\/tags?post=26"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}