{"id":825,"date":"2024-09-11T10:54:51","date_gmt":"2024-09-11T02:54:51","guid":{"rendered":"https:\/\/thereisno.top\/?p=825"},"modified":"2024-10-22T15:30:46","modified_gmt":"2024-10-22T07:30:46","slug":"mysql%e5%af%bc%e5%87%ba%e6%95%b0%e6%8d%ae%e5%ba%93","status":"publish","type":"post","link":"https:\/\/thereisno.top\/?p=825","title":{"rendered":"mysql\u5bfc\u51fa\u6570\u636e\u5e93"},"content":{"rendered":"\n<p><strong>mysqldump \u5bfc\u51fa\u8868\u4f5c\u4e3a\u539f\u59cb\u6570\u636e<\/strong><\/p>\n\n\n\n<p>mysqldump \u662f MySQL \u63d0\u4f9b\u7684\u7528\u4e8e\u5907\u4efd\u548c\u5bfc\u51fa\u6570\u636e\u5e93\u7684\u547d\u4ee4\u884c\u5de5\u5177\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<p><strong>mysqldump<\/strong>&nbsp;\u662f mysql \u7528\u4e8e\u8f6c\u5b58\u50a8\u6570\u636e\u5e93\u7684\u5b9e\u7528\u7a0b\u5e8f\u3002\u5b83\u4e3b\u8981\u4ea7\u751f\u4e00\u4e2a SQL \u811a\u672c\uff0c\u5176\u4e2d\u5305\u542b\u4ece\u5934\u91cd\u65b0\u521b\u5efa\u6570\u636e\u5e93\u6240\u5fc5\u9700\u7684\u547d\u4ee4 CREATE TABLE INSERT \u7b49\u3002<\/p>\n\n\n\n<p>\u4f7f\u7528&nbsp;<strong>mysqldump<\/strong>&nbsp;\u5bfc\u51fa\u6570\u636e\u9700\u8981\u4f7f\u7528&nbsp;<strong>&#8211;tab<\/strong>&nbsp;\u9009\u9879\u6765\u6307\u5b9a\u5bfc\u51fa\u6587\u4ef6\u6307\u5b9a\u7684\u76ee\u5f55\uff0c\u8be5\u76ee\u6807\u5fc5\u987b\u662f\u53ef\u5199\u7684\u3002<\/p>\n\n\n\n<p>mysqldump \u57fa\u672c\u7684\u7528\u6cd5\uff1a<\/p>\n\n\n\n<p>mysqldump -u username -p password -h hostname database_name &gt; output_file.sql<\/p>\n\n\n\n<p><strong>\u53c2\u6570\u8bf4\u660e\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>-u: \u6307\u5b9a MySQL \u7528\u6237\u540d\u3002<\/li>\n\n\n\n<li>-p: \u63d0\u793a\u8f93\u5165\u5bc6\u7801\u3002<\/li>\n\n\n\n<li>-h: \u6307\u5b9a MySQL \u4e3b\u673a\u540d\u3002<\/li>\n\n\n\n<li>database_name: \u8981\u5bfc\u51fa\u7684\u6570\u636e\u5e93\u540d\u79f0\u3002<\/li>\n\n\n\n<li>output_file.sql: \u5bfc\u51fa\u6570\u636e\u4fdd\u5b58\u5230\u7684\u6587\u4ef6\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u4ee5\u4e0b\u5b9e\u4f8b\u5c06\u6570\u636e\u8868 runoob_tbl \u5bfc\u51fa\u5230 \/tmp \u76ee\u5f55\u4e2d\uff1a<\/p>\n\n\n\n<p>$ mysqldump -u root -p &#8211;no-create-info \\<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8211;tab=\/tmp RUNOOB runoob_tbl<br>password ******<\/p>\n\n\n\n<p><strong>mysqldump \u5b9e\u4f8b<\/strong><\/p>\n\n\n\n<p><strong>1. \u5bfc\u51fa\u6574\u4e2a\u6570\u636e\u5e93<\/strong><\/p>\n\n\n\n<p>\u5bfc\u51fa mydatabase \u6570\u636e\u5e93\u5230 mydatabase_backup.sql \u6587\u4ef6\uff1a<\/p>\n\n\n\n<p>mysqldump -u root -p mydatabase &gt; mydatabase_backup.sql<\/p>\n\n\n\n<p><strong>2. \u5bfc\u51fa\u7279\u5b9a\u8868<\/strong><\/p>\n\n\n\n<p>\u5982\u679c\u4f60\u53ea\u60f3\u5bfc\u51fa\u6570\u636e\u5e93\u4e2d\u7684\u67d0\u4e2a\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n\n\n\n<p>mysqldump -u username -p password -h hostname database_name table_name &gt; output_file.sql<\/p>\n\n\n\n<p>\u6216\uff1a<\/p>\n\n\n\n<p>mysqldump -u root -p mydatabase mytable &gt; mytable_backup.sql<\/p>\n\n\n\n<p><strong>3. \u5bfc\u51fa\u6570\u636e\u5e93\u7ed3\u6784<\/strong><\/p>\n\n\n\n<p>\u5982\u679c\u53ea\u60f3\u5bfc\u51fa\u6570\u636e\u5e93\u7ed3\u6784\u800c\u4e0d\u5305\u62ec\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528&nbsp;<strong>&#8211;no-data&nbsp;<\/strong>\u9009\u9879\uff1a<\/p>\n\n\n\n<p>mysqldump -u username -p password -h hostname &#8211;no-data database_name &gt; output_file.sql<\/p>\n\n\n\n<p><strong>4. \u5bfc\u51fa\u538b\u7f29\u6587\u4ef6<\/strong><\/p>\n\n\n\n<p>\u4f60\u53ef\u4ee5\u5c06\u5bfc\u51fa\u7684\u6570\u636e\u8fdb\u884c\u538b\u7f29\uff0c\u4ee5\u51cf\u5c0f\u6587\u4ef6\u5927\u5c0f\u3002\u4f8b\u5982\uff0c\u4f7f\u7528 gzip\uff1a<\/p>\n\n\n\n<p>mysqldump -u username -p password -h hostname database_name | gzip &gt; output_file.sql.gz<\/p>\n\n\n\n<p><strong>\u5bfc\u51fa SQL \u683c\u5f0f\u7684\u6570\u636e<\/strong><\/p>\n\n\n\n<p>\u5bfc\u51fa SQL \u683c\u5f0f\u7684\u6570\u636e\u5230\u6307\u5b9a\u6587\u4ef6\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<p>$ mysqldump -u root -p RUNOOB runoob_tbl &gt; dump.txt<br>password ******<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u547d\u4ee4\u521b\u5efa\u7684\u6587\u4ef6\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>&#8212; MySQL dump 8.23<br>&#8212;<br>&#8212; Host: localhost&nbsp;&nbsp;&nbsp; Database: RUNOOB<br>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br>&#8212; Server version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3.23.58<\/p>\n\n\n\n<p>&#8212;<br>&#8212; Table structure for table `runoob_tbl`<br>&#8212;<\/p>\n\n\n\n<p>CREATE TABLE runoob_tbl (<br>&nbsp; runoob_id int(11) NOT NULL auto_increment,<br>&nbsp; runoob_title varchar(100) NOT NULL default &#8221;,<br>&nbsp; runoob_author varchar(40) NOT NULL default &#8221;,<br>&nbsp; submission_date date default NULL,<br>&nbsp; PRIMARY KEY&nbsp; (runoob_id),<br>&nbsp; UNIQUE KEY AUTHOR_INDEX (runoob_author)<br>) TYPE=MyISAM;<\/p>\n\n\n\n<p>&#8212;<br>&#8212; Dumping data for table `runoob_tbl`<br>&#8212;<\/p>\n\n\n\n<p>INSERT INTO runoob_tbl<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VALUES (1,&#8217;Learn PHP&#8217;,&#8217;John Poul&#8217;,&#8217;2007-05-24&#8242;);<br>INSERT INTO runoob_tbl<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VALUES (2,&#8217;Learn MySQL&#8217;,&#8217;Abdul S&#8217;,&#8217;2007-05-24&#8242;);<br>INSERT INTO runoob_tbl<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VALUES (3,&#8217;JAVA Tutorial&#8217;,&#8217;Sanjay&#8217;,&#8217;2007-05-06&#8242;);<\/p>\n\n\n\n<p>\u5982\u679c\u4f60\u9700\u8981\u5bfc\u51fa\u6574\u4e2a\u6570\u636e\u5e93\u7684\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n\n\n\n<p>$ mysqldump -u root -p RUNOOB &gt; database_dump.txt<br>password ******<\/p>\n\n\n\n<p>\u5982\u679c\u9700\u8981\u5907\u4efd\u6240\u6709\u6570\u636e\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n\n\n\n<p>$ mysqldump -u root -p &#8211;all-databases &gt; database_dump.txt<br>password ******<\/p>\n\n\n\n<p>&#8211;all-databases \u9009\u9879\u5728 MySQL 3.23.12 \u53ca\u4ee5\u540e\u7248\u672c\u52a0\u5165\u3002<\/p>\n\n\n\n<p>\u8be5\u65b9\u6cd5\u53ef\u7528\u4e8e\u5b9e\u73b0\u6570\u636e\u5e93\u7684\u5907\u4efd\u7b56\u7565\u3002<\/p>\n\n\n\n<p><strong>\u5c06\u6570\u636e\u8868\u53ca\u6570\u636e\u5e93\u62f7\u8d1d\u81f3\u5176\u4ed6\u4e3b\u673a<\/strong><\/p>\n\n\n\n<p>\u5982\u679c\u4f60\u9700\u8981\u5c06\u6570\u636e\u62f7\u8d1d\u81f3\u5176\u4ed6\u7684 MySQL \u670d\u52a1\u5668\u4e0a, \u4f60\u53ef\u4ee5\u5728 mysqldump \u547d\u4ee4\u4e2d\u6307\u5b9a\u6570\u636e\u5e93\u540d\u53ca\u6570\u636e\u8868\u3002<\/p>\n\n\n\n<p>\u5728\u6e90\u4e3b\u673a\u4e0a\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5c06\u6570\u636e\u5907\u4efd\u81f3 dump.txt \u6587\u4ef6\u4e2d:<\/p>\n\n\n\n<p>$ mysqldump -u root -p database_name table_name &gt; dump.txt<br>password *****<\/p>\n\n\n\n<p>\u5982\u679c\u5b8c\u6574\u5907\u4efd\u6570\u636e\u5e93\uff0c\u5219\u65e0\u9700\u4f7f\u7528\u7279\u5b9a\u7684\u8868\u540d\u79f0\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u4f60\u9700\u8981\u5c06\u5907\u4efd\u7684\u6570\u636e\u5e93\u5bfc\u5165\u5230MySQL\u670d\u52a1\u5668\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f60\u9700\u8981\u786e\u8ba4\u6570\u636e\u5e93\u5df2\u7ecf\u521b\u5efa\uff1a<\/p>\n\n\n\n<p>$ mysql -u root -p database_name &lt; dump.txt<br>password *****<\/p>\n\n\n\n<p>\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5c06\u5bfc\u51fa\u7684\u6570\u636e\u76f4\u63a5\u5bfc\u5165\u5230\u8fdc\u7a0b\u7684\u670d\u52a1\u5668\u4e0a\uff0c\u4f46\u8bf7\u786e\u4fdd\u4e24\u53f0\u670d\u52a1\u5668\u662f\u76f8\u901a\u7684\uff0c\u662f\u53ef\u4ee5\u76f8\u4e92\u8bbf\u95ee\u7684\uff1a<\/p>\n\n\n\n<p>$ mysqldump -u root -p database_name \\<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | mysql -h other-host.com database_name<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u547d\u4ee4\u4e2d\u4f7f\u7528\u4e86\u7ba1\u9053\u6765\u5c06\u5bfc\u51fa\u7684\u6570\u636e\u5bfc\u5165\u5230\u6307\u5b9a\u7684\u8fdc\u7a0b\u4e3b\u673a\u4e0a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>mysqldump \u5bfc\u51fa\u8868\u4f5c\u4e3a\u539f\u59cb\u6570\u636e mysqldump \u662f MySQL \u63d0\u4f9b\u7684\u7528\u4e8e\u5907\u4efd\u548c\u5bfc\u51fa\u6570\u636e\u5e93\u7684\u547d\u4ee4\u884c &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/thereisno.top\/?p=825\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cmysql\u5bfc\u51fa\u6570\u636e\u5e93\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37],"tags":[68],"class_list":["post-825","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-mysql"],"_links":{"self":[{"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/posts\/825","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thereisno.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=825"}],"version-history":[{"count":2,"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/posts\/825\/revisions"}],"predecessor-version":[{"id":1307,"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/posts\/825\/revisions\/1307"}],"wp:attachment":[{"href":"https:\/\/thereisno.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thereisno.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thereisno.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}