{"id":6446,"date":"2024-11-14T09:46:20","date_gmt":"2024-11-14T01:46:20","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6446\/"},"modified":"2024-11-14T09:46:20","modified_gmt":"2024-11-14T01:46:20","slug":"mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e8%a2%ab%e5%88%a0%e9%99%a4%e6%80%8e%e4%b9%88%e6%81%a2%e5%a4%8d","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6446\/","title":{"rendered":"mysql\u6570\u636e\u5e93\u88ab\u5220\u9664\u600e\u4e48\u6062\u590d"},"content":{"rendered":"<blockquote><p>\n  \u5982\u679c\u542f\u7528\u4e86 mysql \u4e8c\u8fdb\u5236\u65e5\u5fd7\uff0c\u5219\u53ef\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u6062\u590d\u5df2\u5220\u9664\u7684\u6570\u636e\u5e93\uff1a\u68c0\u67e5 binlog \u6587\u4ef6\u5e76\u590d\u5236 .ibd \u6587\u4ef6\u5230\u65b0\u76ee\u5f55\u3002\u521b\u5efa\u65b0\u6570\u636e\u5e93\u3002\u4ece .ibd \u6587\u4ef6\u6062\u590d\u6570\u636e\u5e93\u3002\u5bfc\u5165\u6570\u636e\uff08\u53ef\u9009\uff09\u3002\u91cd\u65b0\u521b\u5efa\u5916\u952e\uff08\u53ef\u9009\uff09\u3002\u91cd\u65b0\u521b\u5efa\u89c6\u56fe\uff08\u53ef\u9009\uff09\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/05\/2024080507341955556.jpg\" class=\"aligncenter\" title=\"mysql\u6570\u636e\u5e93\u88ab\u5220\u9664\u600e\u4e48\u6062\u590d\u63d2\u56fe\" alt=\"mysql\u6570\u636e\u5e93\u88ab\u5220\u9664\u600e\u4e48\u6062\u590d\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u6062\u590d\u5df2\u5220\u9664\u7684 MySQL \u6570\u636e\u5e93<\/strong><\/p>\n<p>\u5f53 MySQL \u6570\u636e\u5e93\u88ab\u610f\u5916\u5220\u9664\u65f6\uff0c\u6062\u590d\u6570\u636e\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<p><strong>\u6b65\u9aa4 1\uff1a\u68c0\u67e5 binlog \u6587\u4ef6<\/strong><\/p>\n<ul>\n<li>\u5982\u679c\u542f\u7528\u4e86 MySQL \u4e8c\u8fdb\u5236\u65e5\u5fd7\uff08binlog\uff09\uff0c\u5219\u53ef\u4ee5\u4ece\u4e2d\u6062\u590d\u5df2\u5220\u9664\u7684\u6570\u636e\u5e93\u3002<\/li>\n<li>\u5bfc\u822a\u5230 MySQL \u6570\u636e\u76ee\u5f55\uff0c\u901a\u5e38\u4f4d\u4e8e \/var\/lib\/\u3002<\/li>\n<li>\u67e5\u627e .ibd \u6587\u4ef6\uff0c\u8fd9\u4e9b\u6587\u4ef6\u5305\u542b\u6570\u636e\u5e93\u4e2d\u7684\u8868\u3002<\/li>\n<li>\u5c06\u8fd9\u4e9b\u6587\u4ef6\u590d\u5236\u5230\u4e00\u4e2a\u65b0\u76ee\u5f55\u3002<\/li>\n<\/ul>\n<p><strong>\u6b65\u9aa4 2\uff1a\u521b\u5efa\u65b0\u6570\u636e\u5e93<\/strong><\/p>\n<p><span>\u70b9\u51fb\u4e0b\u8f7d<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u7a7a\u6570\u636e\u5e93\uff1a<\/p>\n<pre>CREATE DATABASE &lt;database_name&gt;;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ul>\n<p><strong>\u6b65\u9aa4 3\uff1a\u6062\u590d\u6570\u636e\u5e93<\/strong><\/p>\n<ul>\n<li>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4ece .ibd \u6587\u4ef6\u6062\u590d\u6570\u636e\u5e93\uff1a<\/p>\n<pre>mysql -uroot -p &lt;new_database_name&gt; &lt; &lt;ibd_file_path&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ul>\n<p><strong>\u6b65\u9aa4 4\uff1a\u5bfc\u5165\u6570\u636e\uff08\u53ef\u9009\uff09<\/strong><\/p>\n<ul>\n<li>\n<p>\u5982\u679c\u60a8\u5728\u5220\u9664\u6570\u636e\u5e93\u4e4b\u524d\u5bfc\u51fa\u4e86\u6570\u636e\uff0c\u5219\u53ef\u4ee5\u5c06\u5176\u5bfc\u5165\u65b0\u6570\u636e\u5e93\uff1a<\/p>\n<pre>mysql -uroot -p &lt;new_database_name&gt; &lt; &lt;dump_file_path&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ul>\n<p><strong>\u6b65\u9aa4 5\uff1a\u91cd\u65b0\u521b\u5efa\u5916\u952e\uff08\u53ef\u9009\uff09<\/strong><\/p>\n<ul>\n<li>\n<p>\u5982\u679c\u6570\u636e\u5e93\u4e2d\u5b58\u5728\u5916\u952e\uff0c\u5219\u9700\u8981\u91cd\u65b0\u521b\u5efa\u5b83\u4eec\uff1a<\/p>\n<pre>ALTER TABLE &lt;table_name&gt; ADD FOREIGN KEY (...) REFERENCES ...<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ul>\n<p><strong>\u6b65\u9aa4 6\uff1a\u91cd\u65b0\u521b\u5efa\u89c6\u56fe\uff08\u53ef\u9009\uff09<\/strong><\/p>\n<ul>\n<li>\n<p>\u5982\u679c\u6570\u636e\u5e93\u4e2d\u5b58\u5728\u89c6\u56fe\uff0c\u5219\u9700\u8981\u91cd\u65b0\u521b\u5efa\u5b83\u4eec\uff1a<\/p>\n<pre>CREATE VIEW &lt;view_name&gt; AS &lt;view_definition&gt;;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ul>\n<p><strong>\u63d0\u9192\uff1a<\/strong><\/p>\n<ul>\n<li>\u5728\u6267\u884c\u6062\u590d\u8fc7\u7a0b\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u5df2\u7ecf\u5907\u4efd\u4e86\u73b0\u6709\u7684\u6570\u636e\u3002<\/li>\n<li>\u5982\u679c\u6ca1\u6709\u542f\u7528 MySQL \u4e8c\u8fdb\u5236\u65e5\u5fd7\uff0c\u5219\u53ef\u80fd\u65e0\u6cd5\u6062\u590d\u5220\u9664\u7684\u6570\u636e\u5e93\u3002<\/li>\n<li>\u5982\u679c\u6570\u636e\u5e93\u5305\u542b\u5927\u91cf\u6570\u636e\uff0c\u6062\u590d\u8fc7\u7a0b\u53ef\u80fd\u9700\u8981\u4e00\u4e9b\u65f6\u95f4\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u6570\u636e\u5e93\u88ab\u5220\u9664\u600e\u4e48\u6062\u590d\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\u679c\u542f\u7528\u4e86 mysql \u4e8c\u8fdb\u5236\u65e5\u5fd7\uff0c\u5219\u53ef\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u6062\u590d\u5df2\u5220\u9664\u7684\u6570\u636e\u5e93\uff1a\u68c0\u67e5 binlog \u6587\u4ef6\u5e76\u590d\u5236 .ibd \u6587\u4ef6\u5230\u65b0\u76ee\u5f55\u3002\u521b\u5efa\u65b0\u6570\u636e\u5e93\u3002\u4ece .ibd \u6587\u4ef6\u6062\u590d\u6570\u636e\u5e93\u3002\u5bfc\u5165\u6570\u636e\uff08\u53ef\u9009\uff09\u3002\u91cd\u65b0\u521b\u5efa\u5916\u952e\uff08\u53ef\u9009\uff09\u3002\u91cd\u65b0\u521b\u5efa\u89c6\u56fe\uff08\u53ef\u9009\uff09\u3002 \u5982\u4f55\u6062\u590d\u5df2\u5220\u9664\u7684 MySQL \u6570\u636e\u5e93 \u5f53 MySQL \u6570\u636e\u5e93\u88ab\u610f\u5916\u5220\u9664\u65f6\uff0c\u6062\u590d\u6570\u636e\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a \u6b65\u9aa4 1\uff1a\u68c0\u67e5 binlog \u6587\u4ef6 \u5982\u679c\u542f\u7528\u4e86 MySQL \u4e8c\u8fdb\u5236\u65e5\u5fd7\uff08binlog\uff09\uff0c\u5219\u53ef\u4ee5\u4ece\u4e2d\u6062\u590d\u5df2\u5220\u9664\u7684\u6570\u636e\u5e93\u3002 \u5bfc\u822a\u5230 MySQL \u6570\u636e\u76ee\u5f55\uff0c\u901a\u5e38\u4f4d\u4e8e \/var\/lib\/\u3002 \u67e5\u627e .ibd \u6587\u4ef6\uff0c\u8fd9\u4e9b\u6587\u4ef6\u5305\u542b\u6570\u636e\u5e93\u4e2d\u7684\u8868\u3002 \u5c06\u8fd9\u4e9b\u6587\u4ef6\u590d\u5236\u5230\u4e00\u4e2a\u65b0\u76ee\u5f55\u3002 \u6b65\u9aa4 2\uff1a\u521b\u5efa\u65b0\u6570\u636e\u5e93 \u70b9\u51fb\u4e0b\u8f7d\u201c\u201d\uff1b \u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u7a7a\u6570\u636e\u5e93\uff1a CREATE DATABASE &lt;database_name&gt;; \u767b\u5f55\u540e\u590d\u5236 \u6b65\u9aa4 3\uff1a\u6062\u590d\u6570\u636e\u5e93 \u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4ece .ibd \u6587\u4ef6\u6062\u590d\u6570\u636e\u5e93\uff1a mysql -uroot -p &lt;new_database_name&gt; &lt; &lt;ibd_file_path&gt; \u767b\u5f55\u540e\u590d\u5236 \u6b65\u9aa4 4\uff1a\u5bfc\u5165\u6570\u636e\uff08\u53ef\u9009\uff09 \u5982\u679c\u60a8\u5728\u5220\u9664\u6570\u636e\u5e93\u4e4b\u524d\u5bfc\u51fa\u4e86\u6570\u636e\uff0c\u5219\u53ef\u4ee5\u5c06\u5176\u5bfc\u5165\u65b0\u6570\u636e\u5e93\uff1a mysql -uroot [&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-6446","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6446","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=6446"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6446\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6446"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6446"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6446"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}