{"id":424,"date":"2011-09-01T07:49:48","date_gmt":"2011-09-01T07:49:48","guid":{"rendered":"http:\/\/10sa.com\/sql_stories\/?p=424"},"modified":"2011-09-01T07:49:48","modified_gmt":"2011-09-01T07:49:48","slug":"partitioning-backup-and-restore-table-or-repair-with-option-use_frm","status":"publish","type":"post","link":"http:\/\/10sa.com\/sql_stories\/?p=424","title":{"rendered":"Partitioning: Backup and Restore Table (or Repair with option use_frm)."},"content":{"rendered":"<p>I use data files (.MYD) to keep some big tables for archiving purpose. When I need some archive data I am using to repair the table with option &#8220;use_frm&#8221;.<\/p>\n<pre lang=\"sql\">\r\nmysql> REPAIR TABLE `test_table` use_frm;\r\n<\/pre>\n<p>I think it is the same way how native statement RESTORE TABLE works (which is  is deprecated and is removed in MySQL 5.5). However, option &#8220;use_frm&#8221; works only for non partitioned tables, so if you have only .frm, .par and .MYD files the restore is not so simple.<\/p>\n<p>That is my recipe (you need original DDL create fot the table to restore):<\/p>\n<p>1. Get create DDL for the table;<\/p>\n<p>e.g.:<\/p>\n<pre lang=\"SQL\">\r\nmysql> CREATE TABLE IF NOT EXISTS `test_table` (\r\n  `id` int(10) unsigned NOT NULL COMMENT 'Test table',\r\n  PRIMARY KEY (`id`)\r\n) ENGINE=MyISAM DEFAULT CHARSET=utf8;\r\n<\/pre>\n<p>2. Execute it;<br \/>\n3. Backup it with mysqlhotcopy (my destination is \/tmp);<\/p>\n<pre lang=\"bash\">\r\n.\/mysqlhotcopy -u root -p \"root\" --addtodest --noindices test.\/test_table\/ \/tmp\r\n\r\nLocked 1 tables in 0 seconds.\r\nFlushed tables (`test`.`test_table`) in 0 seconds.\r\nCopying 6 files...\r\nCopying indices for 4 files...\r\nUnlocked tables.\r\nmysqlhotcopy copied 1 tables (6 files) in 0 seconds (0 seconds overall).\r\n<\/pre>\n<p>4. Copy your backup files (MYD) to destination conforming to this from mysqlhotcopy (\/tmp);<\/p>\n<pre lang=\"bash\">\r\ncp -p \/backup_mysql\/test\/test* \/tmp -v;\r\n<\/pre>\n<p>5. Recover indices of each partition separately with myisamchk<\/p>\n<pre lang=\"bash\">\r\nmysql> .\/myisamchk -r  \"\/tmp\/test_table#P#p0\"\r\nmysql> .\/myisamchk -r  \"\/tmp\/test_table#P#p1\"\r\nmysql> .\/myisamchk -r  \"\/tmp\/test_table#P#p2\"\r\nmysql> .\/myisamchk -r  \"\/tmp\/test_table#P#p3\"\r\n<\/pre>\n<p>Your table is ready to use (you can copy it to datadir and flush tables);<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I use data files (.MYD) to keep some big tables for archiving purpose. When I need some archive data I am using to repair the table with option &#8220;use_frm&#8221;. mysql> REPAIR TABLE `test_table` use_frm; I think it is the same way how native statement RESTORE TABLE works (which is is deprecated and is removed in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=\/wp\/v2\/posts\/424"}],"collection":[{"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=424"}],"version-history":[{"count":10,"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=\/wp\/v2\/posts\/424\/revisions"}],"predecessor-version":[{"id":435,"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=\/wp\/v2\/posts\/424\/revisions\/435"}],"wp:attachment":[{"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=424"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=424"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}