{"id":158,"date":"2009-07-06T19:04:46","date_gmt":"2009-07-06T19:04:46","guid":{"rendered":"http:\/\/dev001.dl\/yan\/wdp\/?p=158"},"modified":"2026-01-20T05:06:49","modified_gmt":"2026-01-20T05:06:49","slug":"mysqldump","status":"publish","type":"post","link":"http:\/\/www.lalife.net\/?p=158","title":{"rendered":"mysqldump"},"content":{"rendered":"<p>1. dump all database into backup file<\/p>\n<p>mysqldump &#8211;opt \u00a0&#8211;all-databases &gt; \/tmp\/databkup<\/p>\n<p>(&#8211;opt includes lock table option)<\/p>\n<p>2. dump several databases<\/p>\n<p>mysqldump &#8211;opt\u00a0&#8211;databases db1 db2 db3 &gt; \/tmp\/databkup<\/p>\n<p>3. dump single table<\/p>\n<p>mysqldump &#8211;opt db1 table1\u00a0&gt; \/tmp\/databkup<\/p>\n<p>Touble shooting<br \/>\nError: Access denied for user x@y to database z when using lock tables<br \/>\nmysqldump -u username -p database &#8211;single-transaction >dump.sql<\/p>\n<p>User tar to back up db<\/p>\n<p>mysql&gt;\u00a0FLUSH TABLES WITH READ LOCK;<\/p>\n<p>(This will lock the db so it won&#8217;t be updated by other threads. Write threads by other process will wait till the lock is released)<\/p>\n<p>#tar cvzf \/var\/tmp\/datadump.tgz \/var\/lib\/mysql\/*<\/p>\n<p>mysql&gt;\u00a0UNLOCK TABLES;<\/p>\n<div id=\"_mcePaste\"><strong>Restore data<\/strong><\/div>\n<div id=\"_mcePaste\">lock tables bbb write;<\/div>\n<div id=\"_mcePaste\">mysql bbb &lt; \/data_backup\/databkup<\/div>\n<div id=\"_mcePaste\">unlock tables;<\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. dump all database into backup file mysqldump &#8211;opt \u00a0&#8211;all-databases &gt; \/tmp\/databkup (&#8211;opt includes lock table option) 2. dump several databases mysqldump &#8211;opt\u00a0&#8211;databases db1 db2 db3 &gt; \/tmp\/databkup 3. dump single table mysqldump &#8211;opt db1 table1\u00a0&gt; \/tmp\/databkup Touble shooting Error: &hellip; <a href=\"http:\/\/www.lalife.net\/?p=158\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33,19,27],"tags":[],"class_list":["post-158","post","type-post","status-publish","format-standard","hentry","category-linux-command","category-mysql","category-unix-command"],"_links":{"self":[{"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/posts\/158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.lalife.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=158"}],"version-history":[{"count":1,"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/posts\/158\/revisions"}],"predecessor-version":[{"id":1956,"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/posts\/158\/revisions\/1956"}],"wp:attachment":[{"href":"http:\/\/www.lalife.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.lalife.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=158"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.lalife.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}