{"id":1709,"date":"2009-03-29T15:45:07","date_gmt":"2009-03-29T19:45:07","guid":{"rendered":"http:\/\/blogs.n1zyy.com\/n1zyy\/?p=1709"},"modified":"2009-03-29T15:45:07","modified_gmt":"2009-03-29T19:45:07","slug":"show-create-table","status":"publish","type":"post","link":"https:\/\/blogs.n1zyy.com\/n1zyy\/2009\/03\/29\/show-create-table\/","title":{"rendered":"SHOW CREATE TABLE"},"content":{"rendered":"<p>Silly MySQL trick of the day. This is probably no stranger to those work with MySQL all the time, but it&#8217;s a nice trick to have up your sleeve.<\/p>\n<p>For reasons I still can&#8217;t wrap my head around, one of the MySQL tables we need for Cacti just up and vanished. It&#8217;s not really used for anything essential, so it&#8217;s not a great loss, just really annoying. So I need to recreate it. Fortunately, I have MySQL running on another machine.<\/p>\n<pre><strong>mysql> desc poller_output;<\/strong>\n+---------------+-----------------------+------+-----+---------------------+-------+\n| Field         | Type                  | Null | Key | Default             | Extra |\n+---------------+-----------------------+------+-----+---------------------+-------+\n| local_data_id | mediumint(8) unsigned | NO   | PRI | 0                   |       |\n| rrd_name      | varchar(19)           | NO   | PRI | NULL                |       |\n| time          | datetime              | NO   | PRI | 0000-00-00 00:00:00 |       |\n| output        | text                  | NO   |     | NULL                |       |\n+---------------+-----------------------+------+-----+---------------------+-------+\n4 rows in set (0.00 sec)\n<\/pre>\n<p>It&#8217;s not that complicated. I could take a second and write out the CREATE TABLE statement I&#8217;d need to run on the machine missing the table. But here&#8217;s a neat trick (run on the system with the table, obviously):<\/p>\n<pre><strong>mysql> show create table poller_outputG<\/strong>\n*************************** 1. row ***************************\n       Table: poller_output\nCreate Table: CREATE TABLE `poller_output` (\n  `local_data_id` mediumint(8) unsigned NOT NULL default '0',\n  `rrd_name` varchar(19) NOT NULL default '',\n  `time` datetime NOT NULL default '0000-00-00 00:00:00',\n  `output` text NOT NULL,\n  PRIMARY KEY  (`local_data_id`,`rrd_name`,`time`)\n) ENGINE=MyISAM DEFAULT CHARSET=latin1\n1 row in set (0.00 sec)\n<\/pre>\n<p>Why write out the CREATE TABLE statement when we can just let MySQL tell us exactly how to re-create a table? I initially discovered this with the considerably more complex issue of views (SHOW CREATE VIEW), but it extends to tables, too. So now we can just copy-and-paste. Viola!<\/p>\n<p>Well not viola for me, but viola for anyone whose filesystem hasn&#8217;t gone corrupt.<\/p>","protected":false},"excerpt":{"rendered":"<p>Silly MySQL trick of the day. This is probably no stranger to those work with MySQL all the time, but it&#8217;s a nice trick to have up your sleeve. For reasons I still can&#8217;t wrap my head around, one of &hellip; <a href=\"https:\/\/blogs.n1zyy.com\/n1zyy\/2009\/03\/29\/show-create-table\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,13],"tags":[],"class_list":["post-1709","post","type-post","status-publish","format-standard","hentry","category-computers","category-linux-tips"],"_links":{"self":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts\/1709","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/comments?post=1709"}],"version-history":[{"count":0,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts\/1709\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/media?parent=1709"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/categories?post=1709"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/tags?post=1709"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}