{"id":5121,"date":"2024-11-14T09:35:14","date_gmt":"2024-11-14T01:35:14","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5121\/"},"modified":"2024-11-14T09:35:14","modified_gmt":"2024-11-14T01:35:14","slug":"mysql%e6%80%8e%e4%b9%88%e6%8b%b7%e8%b4%9d%e6%95%b0%e6%8d%ae%e5%ba%93","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5121\/","title":{"rendered":"mysql\u600e\u4e48\u62f7\u8d1d\u6570\u636e\u5e93"},"content":{"rendered":"<blockquote><p>\n  \u5982\u4f55\u4f7f\u7528 mysql \u62f7\u8d1d\u6570\u636e\u5e93\uff1f\u76f4\u63a5\u65b9\u6cd5\uff1a\u5bfc\u51fa\u6570\u636e\u5e93\uff1a\u4f7f\u7528 mysqldump\u5bfc\u5165\u6570\u636e\u5e93\uff1a\u4f7f\u7528 mysql\u590d\u5236\u65b9\u6cd5\uff1a\u521b\u5efa\u65b0\u6570\u636e\u5e93\u5e76\u4ece\u73b0\u6709\u6570\u636e\u5e93\u590d\u5236\u6570\u636e\uff1acreate database&#8230;select\u5c06\u6570\u636e\u590d\u5236\u5230\u5176\u4ed6\u8868\uff1ainsert into&#8230;select\u9644\u52a0\u9009\u9879\uff1a\u6307\u5b9a\u590d\u5236\u8868\uff1awhere \u5b50\u53e5\u8fc7\u6ee4\u6570\u636e\uff1awhere \u5b50\u53e5\u538b\u7f29\u5907\u4efd\uff1a&#8211;compress \u9009\u9879\u4f7f\u7528\u7ba1\u9053\uff1a\u5c06 mysqldump \u8f93\u51fa\u4f20\u8f93\u5230\u5bfc\u5165\u547d\u4ee4\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/22\/2024052214153394649.jpg\" class=\"aligncenter\" title=\"mysql\u600e\u4e48\u62f7\u8d1d\u6570\u636e\u5e93\u63d2\u56fe\" alt=\"mysql\u600e\u4e48\u62f7\u8d1d\u6570\u636e\u5e93\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 MySQL \u62f7\u8d1d\u6570\u636e\u5e93<\/strong><\/p>\n<p><strong>\u76f4\u63a5\u65b9\u6cd5\uff1a\u4f7f\u7528 MySQLdump<\/strong><\/p>\n<ul>\n<li> <strong>\u5bfc\u51fa\u6570\u636e\u5e93\uff1a<\/strong> dump -u username -p database-name &gt; new-database.sql<\/li>\n<li> <strong>\u5bfc\u5165\u6570\u636e\u5e93\uff1a<\/strong> mysql -u username -p database-name <\/li>\n<\/ul>\n<p><strong>\u590d\u5236\u65b9\u6cd5\uff1a\u4f7f\u7528 CREATE&#8230;SELECT \u8bed\u53e5<\/strong><\/p>\n<ul>\n<li> <strong>\u4ece\u73b0\u6709\u6570\u636e\u5e93\u521b\u5efa\u65b0\u6570\u636e\u5e93\uff1a<\/strong> CREATE DATABASE new_database AS SELECT * FROM existing_database;<\/li>\n<li> <strong>\u5c06\u6570\u636e\u4ece\u4e00\u4e2a\u8868\u590d\u5236\u5230\u53e6\u4e00\u4e2a\u8868\uff1a<\/strong> INSERT INTO new_table SELECT * FROM existing_table;<\/li>\n<\/ul>\n<p><strong>\u9644\u52a0\u9009\u9879<\/strong><\/p>\n<ul>\n<li> <strong>\u6307\u5b9a\u8981\u590d\u5236\u7684\u8868\uff1a<\/strong> \u5728 CREATE&#8230;SELECT \u6216 INSERT \u8bed\u53e5\u4e2d\u4f7f\u7528 WHERE \u5b50\u53e5\u6765\u9009\u62e9\u8981\u590d\u5236\u7684\u7279\u5b9a\u8868\u3002<\/li>\n<li> <strong>\u4f7f\u7528 WHERE \u5b50\u53e5\u8fc7\u6ee4\u6570\u636e\uff1a<\/strong> \u5c06 WHERE \u5b50\u53e5\u6dfb\u52a0\u5230 INSERT \u8bed\u53e5\u4e2d\u4ee5\u4ec5\u590d\u5236\u7b26\u5408\u7279\u5b9a\u6761\u4ef6\u7684\u6570\u636e\u3002<\/li>\n<li> <strong>\u538b\u7f29\u5907\u4efd\uff1a<\/strong> \u4f7f\u7528 &#8211;compress \u9009\u9879\u8fdb\u884c\u5bfc\u51fa\u65f6\u5bf9 MySQLdump \u8f93\u51fa\u8fdb\u884c\u538b\u7f29\u3002<\/li>\n<li> <strong>\u4f7f\u7528\u7ba1\u9053\uff1a<\/strong> \u5c06 mysqldump \u8f93\u51fa\u76f4\u63a5\u4f20\u8f93\u5230\u5bfc\u5165\u547d\u4ee4\uff0c\u4ee5\u8282\u7701\u4e2d\u95f4\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<pre># \u5bfc\u51fa\u540d\u4e3a \"old_database\" \u7684\u6570\u636e\u5e93\nmysqldump -u root -p old_database &gt; old_database.sql\n\n# \u4ece old_database \u521b\u5efa\u65b0\u6570\u636e\u5e93 \"new_database\"\nCREATE DATABASE new_database AS SELECT * FROM old_database;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u63d0\u793a<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u5728\u6267\u884c\u590d\u5236\u64cd\u4f5c\u4e4b\u524d\u62e5\u6709\u6240\u9700\u7684\u6743\u9650\u3002<\/li>\n<li>\u590d\u5236\u64cd\u4f5c\u53ef\u80fd\u9700\u8981\u5927\u91cf\u65f6\u95f4\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u6570\u636e\u5e93\u7684\u5927\u5c0f\u3002<\/li>\n<li>\u5b9a\u671f\u5907\u4efd\u6570\u636e\u5e93\u4ee5\u786e\u4fdd\u6570\u636e\u5b89\u5168\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u62f7\u8d1d\u6570\u636e\u5e93\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528 mysql \u62f7\u8d1d\u6570\u636e\u5e93\uff1f\u76f4\u63a5\u65b9\u6cd5\uff1a\u5bfc\u51fa\u6570\u636e\u5e93\uff1a\u4f7f\u7528 mysqldump\u5bfc\u5165\u6570\u636e\u5e93\uff1a\u4f7f\u7528 mysql\u590d\u5236\u65b9\u6cd5\uff1a\u521b\u5efa\u65b0\u6570\u636e\u5e93\u5e76\u4ece\u73b0\u6709\u6570\u636e\u5e93\u590d\u5236\u6570\u636e\uff1acreate database&#8230;select\u5c06\u6570\u636e\u590d\u5236\u5230\u5176\u4ed6\u8868\uff1ainsert into&#8230;select\u9644\u52a0\u9009\u9879\uff1a\u6307\u5b9a\u590d\u5236\u8868\uff1awhere \u5b50\u53e5\u8fc7\u6ee4\u6570\u636e\uff1awhere \u5b50\u53e5\u538b\u7f29\u5907\u4efd\uff1a&#8211;compress \u9009\u9879\u4f7f\u7528\u7ba1\u9053\uff1a\u5c06 mysqldump \u8f93\u51fa\u4f20\u8f93\u5230\u5bfc\u5165\u547d\u4ee4 \u5982\u4f55\u4f7f\u7528 MySQL \u62f7\u8d1d\u6570\u636e\u5e93 \u76f4\u63a5\u65b9\u6cd5\uff1a\u4f7f\u7528 MySQLdump \u5bfc\u51fa\u6570\u636e\u5e93\uff1a dump -u username -p database-name &gt; new-database.sql \u5bfc\u5165\u6570\u636e\u5e93\uff1a mysql -u username -p database-name \u590d\u5236\u65b9\u6cd5\uff1a\u4f7f\u7528 CREATE&#8230;SELECT \u8bed\u53e5 \u4ece\u73b0\u6709\u6570\u636e\u5e93\u521b\u5efa\u65b0\u6570\u636e\u5e93\uff1a CREATE DATABASE new_database AS SELECT * FROM existing_database; \u5c06\u6570\u636e\u4ece\u4e00\u4e2a\u8868\u590d\u5236\u5230\u53e6\u4e00\u4e2a\u8868\uff1a INSERT INTO new_table SELECT * FROM existing_table; \u9644\u52a0\u9009\u9879 \u6307\u5b9a\u8981\u590d\u5236\u7684\u8868\uff1a \u5728 CREATE&#8230;SELECT [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5121","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5121","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=5121"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5121\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5121"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}