{"id":324,"date":"2023-09-02T14:25:41","date_gmt":"2023-09-02T06:25:41","guid":{"rendered":"https:\/\/muchen.fan\/?p=324"},"modified":"2024-03-22T00:14:59","modified_gmt":"2024-03-21T16:14:59","slug":"%e6%95%b0%e6%8d%ae%e5%ba%93%e5%a4%87%e4%bb%bd%e5%b7%a5%e5%85%b7mysqldump%e5%b0%8f%e6%8a%84","status":"publish","type":"post","link":"https:\/\/muchen.fan\/?p=324","title":{"rendered":"\u6570\u636e\u5e93\u5907\u4efd\u5de5\u5177mysqldump\u901f\u67e5\u8868"},"content":{"rendered":"<p>\u5f53\u4f60\u9700\u8981\u5907\u4efd\u548c\u6062\u590dMySQL\u6570\u636e\u5e93\u65f6\uff0cmysqldump\u662f\u4e00\u4e2a\u975e\u5e38\u6709\u7528\u7684\u5de5\u5177\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u8be6\u5c3d\u7684mysqldump cheatsheet\uff0c\u5305\u62ec\u5e38\u7528\u7684mysqldump\u547d\u4ee4\u548c\u9009\u9879\uff0c\u4ee5\u53ca\u4e00\u4e9b\u5e38\u89c1\u7684\u7528\u4f8b\u793a\u4f8b\u3002<\/p>\n<p><strong>1. \u57fa\u672c\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre><code class=\"language-bash\">mysqldump -u [\u7528\u6237\u540d] -p[\u5bc6\u7801] [\u6570\u636e\u5e93\u540d] &gt; [\u8f93\u51fa\u6587\u4ef6\u540d].sql<\/code><\/pre>\n<ul>\n<li><code>-u<\/code>\uff1a\u6307\u5b9a\u7528\u6237\u540d\u3002<\/li>\n<li><code>-p<\/code>\uff1a\u5728\u4e0d\u8f93\u5165\u5bc6\u7801\u7684\u60c5\u51b5\u4e0b\u63d0\u793a\u8f93\u5165\u5bc6\u7801\u3002<\/li>\n<li><code>[\u6570\u636e\u5e93\u540d]<\/code>\uff1a\u8981\u5907\u4efd\u7684\u6570\u636e\u5e93\u540d\u79f0\u3002<\/li>\n<li><code>[\u8f93\u51fa\u6587\u4ef6\u540d].sql<\/code>\uff1a\u5c06\u5907\u4efd\u8f93\u51fa\u5230\u7684\u6587\u4ef6\u540d\u3002<\/li>\n<\/ul>\n<p><strong>2. \u5907\u4efd\u6574\u4e2a\u6570\u636e\u5e93\uff1a<\/strong><\/p>\n<pre><code class=\"language-bash\">mysqldump -u [\u7528\u6237\u540d] -p[\u5bc6\u7801] [\u6570\u636e\u5e93\u540d] &gt; [\u8f93\u51fa\u6587\u4ef6\u540d].sql<\/code><\/pre>\n<p><strong>3. \u5907\u4efd\u591a\u4e2a\u6570\u636e\u5e93\uff1a<\/strong><\/p>\n<pre><code class=\"language-bash\">mysqldump -u [\u7528\u6237\u540d] -p[\u5bc6\u7801] --databases [\u6570\u636e\u5e931] [\u6570\u636e\u5e932] &gt; [\u8f93\u51fa\u6587\u4ef6\u540d].sql<\/code><\/pre>\n<p><strong>4. \u5907\u4efd\u6240\u6709\u6570\u636e\u5e93\uff1a<\/strong><\/p>\n<pre><code class=\"language-bash\">mysqldump -u [\u7528\u6237\u540d] -p[\u5bc6\u7801] --all-databases &gt; [\u8f93\u51fa\u6587\u4ef6\u540d].sql<\/code><\/pre>\n<p><strong>5. \u4ec5\u5907\u4efd\u6570\u636e\u5e93\u7ed3\u6784\uff08\u65e0\u6570\u636e\uff09\uff1a<\/strong><\/p>\n<pre><code class=\"language-bash\">mysqldump -u [\u7528\u6237\u540d] -p[\u5bc6\u7801] --no-data [\u6570\u636e\u5e93\u540d] &gt; [\u8f93\u51fa\u6587\u4ef6\u540d].sql<\/code><\/pre>\n<p><strong>6. \u4ec5\u5907\u4efd\u6570\u636e\u5e93\u6570\u636e\uff08\u65e0\u7ed3\u6784\uff09\uff1a<\/strong><\/p>\n<pre><code class=\"language-bash\">mysqldump -u [\u7528\u6237\u540d] -p[\u5bc6\u7801] --no-create-info [\u6570\u636e\u5e93\u540d] &gt; [\u8f93\u51fa\u6587\u4ef6\u540d].sql<\/code><\/pre>\n<p><strong>7. \u5907\u4efd\u7279\u5b9a\u8868\uff1a<\/strong><\/p>\n<pre><code class=\"language-bash\">mysqldump -u [\u7528\u6237\u540d] -p[\u5bc6\u7801] [\u6570\u636e\u5e93\u540d] [\u8868\u540d] &gt; [\u8f93\u51fa\u6587\u4ef6\u540d].sql<\/code><\/pre>\n<p><strong>8. \u6dfb\u52a0CREATE DATABASE\u8bed\u53e5\u5230\u5907\u4efd\u6587\u4ef6\uff1a<\/strong><\/p>\n<pre><code class=\"language-bash\">mysqldump -u [\u7528\u6237\u540d] -p[\u5bc6\u7801] --databases [\u6570\u636e\u5e93\u540d] --add-drop-database &gt; [\u8f93\u51fa\u6587\u4ef6\u540d].sql<\/code><\/pre>\n<p><strong>9. \u538b\u7f29\u5907\u4efd\u6587\u4ef6\uff1a<\/strong><\/p>\n<pre><code class=\"language-bash\">mysqldump -u [\u7528\u6237\u540d] -p[\u5bc6\u7801] [\u6570\u636e\u5e93\u540d] | gzip &gt; [\u8f93\u51fa\u6587\u4ef6\u540d].sql.gz<\/code><\/pre>\n<p><strong>10. \u6062\u590d\u6570\u636e\u5e93\uff1a<\/strong><\/p>\n<pre><code class=\"language-bash\">mysql -u [\u7528\u6237\u540d] -p[\u5bc6\u7801] [\u6570\u636e\u5e93\u540d] &lt; [\u5907\u4efd\u6587\u4ef6].sql<\/code><\/pre>\n<p><strong>11. \u5bfc\u51fa\u7279\u5b9a\u8868\u5230CSV\u6587\u4ef6\uff1a<\/strong><\/p>\n<pre><code class=\"language-bash\">mysqldump -u [\u7528\u6237\u540d] -p[\u5bc6\u7801] --tab=[\u8f93\u51fa\u76ee\u5f55] [\u6570\u636e\u5e93\u540d] [\u8868\u540d]<\/code><\/pre>\n<p><strong>12. \u4ec5\u5907\u4efd\u5b58\u50a8\u8fc7\u7a0b\u548c\u51fd\u6570\uff1a<\/strong><\/p>\n<pre><code class=\"language-bash\">mysqldump -u [\u7528\u6237\u540d] -p[\u5bc6\u7801] --routines [\u6570\u636e\u5e93\u540d] &gt; [\u8f93\u51fa\u6587\u4ef6\u540d].sql<\/code><\/pre>\n<p><strong>13. \u5907\u4efd\u8fdc\u7a0bMySQL\u670d\u52a1\u5668\uff1a<\/strong><\/p>\n<pre><code class=\"language-bash\">mysqldump -h [\u8fdc\u7a0b\u4e3b\u673a] -u [\u7528\u6237\u540d] -p[\u5bc6\u7801] [\u6570\u636e\u5e93\u540d] &gt; [\u8f93\u51fa\u6587\u4ef6\u540d].sql<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u4f60\u9700\u8981\u5907\u4efd\u548c\u6062\u590dMySQL\u6570\u636e\u5e93\u65f6\uff0cmysqldump\u662f\u4e00\u4e2a\u975e\u5e38\u6709\u7528\u7684\u5de5\u5177\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u8be6\u5c3d\u7684mysqldump cheatsheet\uff0c\u5305\u62ec\u5e38\u7528\u7684mysqldump\u547d\u4ee4\u548c\u9009\u9879\uff0c\u4ee5\u53ca\u4e00\u4e9b\u5e38\u89c1\u7684\u7528\u4f8b\u793a\u4f8b\u3002&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-324","post","type-post","status-publish","format-standard","hentry","category-3"],"_links":{"self":[{"href":"https:\/\/muchen.fan\/index.php?rest_route=\/wp\/v2\/posts\/324","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/muchen.fan\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/muchen.fan\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/muchen.fan\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/muchen.fan\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=324"}],"version-history":[{"count":2,"href":"https:\/\/muchen.fan\/index.php?rest_route=\/wp\/v2\/posts\/324\/revisions"}],"predecessor-version":[{"id":326,"href":"https:\/\/muchen.fan\/index.php?rest_route=\/wp\/v2\/posts\/324\/revisions\/326"}],"wp:attachment":[{"href":"https:\/\/muchen.fan\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=324"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/muchen.fan\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=324"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/muchen.fan\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=324"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}