{"id":3817,"date":"2020-08-24T00:42:18","date_gmt":"2020-08-24T08:42:18","guid":{"rendered":"http:\/\/www.hi-alex.com\/?p=3817"},"modified":"2020-08-29T14:52:39","modified_gmt":"2020-08-29T22:52:39","slug":"%e6%8a%98%e8%85%bewordpress-media-library%e5%9c%a8%e8%bf%81%e7%a7%bb%e5%90%8e%e4%b8%8d%e6%98%be%e7%a4%ba%e5%9b%be%e7%89%87","status":"publish","type":"post","link":"http:\/\/www.hi-alex.com\/?p=3817","title":{"rendered":"\u6298\u817eWordPress\u7684Media Library\u5728\u8fc1\u79fb\u540e\u4e0d\u663e\u793a\u56fe\u7247\u7684\u6545\u969c"},"content":{"rendered":"\n<p>\u7528WordPress\u81ea\u5e26\u7684migration tool\u8fc1\u79fb\u5230\u65b0\u670d\u52a1\u5668\uff0c\u4f1a\u9047\u5230\u8fd9\u6837\u7684\u95ee\u9898\uff1a\u867d\u7136\u4e4b\u524d\u4e0a\u4f20\u7684\u7167\u7247\u90fd\u5df2\u7ecf\u62f7\u8d1d\u5230wp-content\/uploads\u76ee\u5f55\u4e0b\uff0c\u4f46\u662f\u5728Media Library\u4e0b\uff0c\u8fd9\u4e9b\u7167\u7247\u90fd\u65e0\u6cd5\u6b63\u5e38\u663e\u793a\uff0c\u539f\u56e0\u662f\u6709\u4e24\u5f20\u8868\u7684\u6570\u636e\u6ca1\u6709\u5bfc\u8fc7\u6765\uff1awp_posts\u548cwp_postmeta\u3002<\/p>\n\n\n\n<p>\u641e\u4e86\u534a\u5929\uff0c\u624d\u627e\u51fa\u89e3\u51b3\u529e\u6cd5\u3002<\/p>\n\n\n\n<p>\u9996\u5148\uff0c\u5728\u65e7\u670d\u52a1\u5668\uff0c\u5bfc\u51fa\u6240\u6709attachment\u7c7b\u578b\u7684posts\uff1a<\/p>\n\n\n\n<p><code>sudo mysqldump wordpress wp_posts --where=\"post_type='attachment'\" &gt; wp_posts.sql<\/code><\/p>\n\n\n\n<p>\u5bfc\u51fa\u6240\u6709\u4e0eattachment\u6709\u5173\u7684wp_postmeta\u8bb0\u5f55\uff1a<\/p>\n\n\n\n<p><code>sudo mysqldump wordpress wp_postmeta --single-transaction --where=\"post_id in (select id from wp_posts where post_type='attachment')\" &gt; wp_postmeta.sql<\/code><\/p>\n\n\n\n<p>\u4e4b\u540e\uff0c\u5c06\u4e24\u4e2asql\u6587\u4ef6\u4e0a\u4f20\u5230\u65b0\u670d\u52a1\u5668\uff0c\u5e76\u5bfc\u5165\u5bf9\u5e94\u6570\u636e\u5e93\uff1a<\/p>\n\n\n\n<p><code>mysql -u root -p wordpress &lt; \/home\/wp_posts.sql<\/code><\/p>\n\n\n\n<p><code>mysql -u root -p wordpress &lt; \/home\/wp_postmeta.sql<\/code><\/p>\n\n\n\n<p>\u8fd9\u4e2a\u65b9\u6cd5\u5b58\u5728\u4e00\u4e2a\u95ee\u9898\uff1a\u5bfc\u51fa\u7684\u8bb0\u5f55\u7684id\u53ef\u80fd\u5728\u65b0\u5b9e\u4f8b\u4e2d\u7684\u8868\u91cc\u5df2\u7ecf\u5b58\u5728\u4e86\uff0c\u8fd9\u5c31\u5f88\u9ebb\u70e6\u4e86\uff0c\u4e00\u4e2a\u529e\u6cd5\u662f\uff0c\u5728sql\u6587\u4ef6\u91cc\u624b\u52a8\u6539\u6389\u51b2\u7a81\u7684id\uff1b\u53e6\u4e00\u79cd\u5c31\u662f\u653e\u5f03\u6240\u6709\u51b2\u7a81\u7684id\uff08\u5728sql\u6587\u4ef6\u624b\u52a8\u5220\u6389\u5bf9\u5e94\u7684\u811a\u672c\uff09\u3002\u6211\u5728wp_posts\u91cc\u4f7f\u7528\u624b\u52a8\u6539id\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u4e00\u5171\u53ea\u6709\u56db\u4e94\u6761\u8bb0\u5f55\u51b2\u7a81\uff1b\u800c\u5728wp_postmeta\u8868\uff0c\u6211\u91c7\u7528\u4e86\u6279\u91cf\u4fee\u6539\u65b0\u63d2\u5165\u8bb0\u5f55\u7684ID\u540e\u5bfc\u5165\u3002\u5177\u4f53\u65b9\u6cd5\u662f\uff0c\u9996\u5148\u5728\u65b0\u5b9e\u4f8b\u7684\u6570\u636e\u5e93\u4e0a\u6267\u884c<\/p>\n\n\n\n<p><code>select max(meta_id) from wp_postmeta;<br>+--------------+<br>| max(meta_id) |<br>+--------------+<br>| 15840        |<br>+--------------+<br><strong>1 row in set (0.00 sec)<\/strong><\/code><\/p>\n\n\n\n<p>\u627e\u51fa\u5f53\u524dwp_postmeta\u8868\u6700\u5927ID\uff0c\u7136\u540e\u7528\u6587\u672c\u7f16\u8f91\u5668\u6253\u5f00wp_postmeta.sql\uff0c\u67e5\u627e&#8221;),(&#8220;\uff0c\u66ff\u6362\u4e3a&#8221;),(15840+&#8221;\uff0c\u4e5f\u5c31\u662f\u5728\u539fID\u7684\u57fa\u7840\u4e0a\u81ea\u589e15840\uff0c\u4ee5\u4fdd\u8bc1\u65b0ID\u4e0d\u5b58\u5728\u3002\u5f53\u7136\uff0c\u811a\u672c\u7b2c\u4e00\u6761\u8bb0\u5f55\u7531\u4e8e\u4e0d\u7b26\u5408&#8221;),(&#8220;\u7684\u683c\u5f0f\uff0c\u6240\u4ee5\u9700\u8981\u624b\u52a8\u4fee\u6539\u4e3a(15840+&#8221;\u3002\u5b8c\u6210\u4ee5\u540e\uff0c\u653e\u5230\u670d\u52a1\u5668\u4e0a\u5bfc\u5165\uff0c\u95ee\u9898\u987a\u5229\u89e3\u51b3\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7528WordPress\u81ea\u5e26\u7684migration tool\u8fc1\u79fb\u5230\u65b0\u670d\u52a1\u5668\uff0c\u4f1a\u9047\u5230\u8fd9\u6837\u7684\u95ee\u9898\uff1a\u867d\u7136\u4e4b\u524d\u4e0a\u4f20\u7684\u7167\u7247\u90fd\u5df2\u7ecf\u62f7\u8d1d\u5230wp-content\/uploads\u76ee\u5f55\u4e0b\uff0c\u4f46\u662f\u5728Media Library\u4e0b\uff0c\u8fd9\u4e9b\u7167\u7247\u90fd\u65e0\u6cd5\u6b63\u5e38\u663e\u793a\uff0c\u539f\u56e0\u662f\u6709\u4e24\u5f20\u8868\u7684\u6570\u636e\u6ca1\u6709\u5bfc\u8fc7\u6765\uff1awp_posts\u548cwp_postmeta\u3002 \u641e\u4e86\u534a\u5929\uff0c\u624d\u627e\u51fa\u89e3\u51b3\u529e\u6cd5\u3002 \u9996\u5148\uff0c\u5728\u65e7\u670d\u52a1\u5668\uff0c\u5bfc\u51fa\u6240\u6709attachment\u7c7b\u578b\u7684posts\uff1a sudo mysqldump wordpress wp_posts &#8211;where=&#8221;post_type=&#8217;attachment'&#8221; &gt; wp_posts.sql \u5bfc\u51fa\u6240\u6709\u4e0eattachment\u6709\u5173\u7684wp_postmeta\u8bb0\u5f55\uff1a sudo mysqldump wordpress wp_postmeta &#8211;single-transaction &#8211;where=&#8221;post_id in (select id from wp_posts where post_type=&#8217;attachment&#8217;)&#8221; &gt; wp_postmeta.sql \u4e4b\u540e\uff0c\u5c06\u4e24\u4e2asql\u6587\u4ef6\u4e0a\u4f20\u5230\u65b0\u670d\u52a1\u5668\uff0c\u5e76\u5bfc\u5165\u5bf9\u5e94\u6570\u636e\u5e93\uff1a mysql -u root -p wordpress &lt; \/home\/wp_posts.sql mysql -u root -p wordpress &lt; \/home\/wp_postmeta.sql \u8fd9\u4e2a\u65b9\u6cd5\u5b58\u5728\u4e00\u4e2a\u95ee\u9898\uff1a\u5bfc\u51fa\u7684\u8bb0\u5f55\u7684id\u53ef\u80fd\u5728\u65b0\u5b9e\u4f8b\u4e2d\u7684\u8868\u91cc\u5df2\u7ecf\u5b58\u5728\u4e86\uff0c\u8fd9\u5c31\u5f88\u9ebb\u70e6\u4e86\uff0c\u4e00\u4e2a\u529e\u6cd5\u662f\uff0c\u5728sql\u6587\u4ef6\u91cc\u624b\u52a8\u6539\u6389\u51b2\u7a81\u7684id\uff1b\u53e6\u4e00\u79cd\u5c31\u662f\u653e\u5f03\u6240\u6709\u51b2\u7a81\u7684id\uff08\u5728sql\u6587\u4ef6\u624b\u52a8\u5220\u6389\u5bf9\u5e94\u7684\u811a\u672c\uff09\u3002\u6211\u5728wp_posts\u91cc\u4f7f\u7528\u624b\u52a8\u6539id\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u4e00\u5171\u53ea\u6709\u56db\u4e94\u6761\u8bb0\u5f55\u51b2\u7a81\uff1b\u800c\u5728wp_postmeta\u8868\uff0c\u6211\u91c7\u7528\u4e86\u6279\u91cf\u4fee\u6539\u65b0\u63d2\u5165\u8bb0\u5f55\u7684ID\u540e\u5bfc\u5165\u3002\u5177\u4f53\u65b9\u6cd5\u662f\uff0c\u9996\u5148\u5728\u65b0\u5b9e\u4f8b\u7684\u6570\u636e\u5e93\u4e0a\u6267\u884c select max(meta_id) from wp_postmeta;+&#8212;&#8212;&#8212;&#8212;&#8211;+| max(meta_id) |+&#8212;&#8212;&#8212;&#8212;&#8211;+| 15840 |+&#8212;&#8212;&#8212;&#8212;&#8211;+1 row in set [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-3817","post","type-post","status-publish","format-standard","hentry","category-the-blog"],"_links":{"self":[{"href":"http:\/\/www.hi-alex.com\/index.php?rest_route=\/wp\/v2\/posts\/3817","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.hi-alex.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.hi-alex.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.hi-alex.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.hi-alex.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3817"}],"version-history":[{"count":7,"href":"http:\/\/www.hi-alex.com\/index.php?rest_route=\/wp\/v2\/posts\/3817\/revisions"}],"predecessor-version":[{"id":3841,"href":"http:\/\/www.hi-alex.com\/index.php?rest_route=\/wp\/v2\/posts\/3817\/revisions\/3841"}],"wp:attachment":[{"href":"http:\/\/www.hi-alex.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3817"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.hi-alex.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3817"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.hi-alex.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3817"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}