{"id":6163,"date":"2024-11-14T12:51:24","date_gmt":"2024-11-14T04:51:24","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6163\/"},"modified":"2024-11-14T12:51:24","modified_gmt":"2024-11-14T04:51:24","slug":"%e5%a6%82%e4%bd%95%e6%89%be%e5%9b%9emysql%e5%af%86%e7%a0%81","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6163\/","title":{"rendered":"\u5982\u4f55\u627e\u56demysql\u5bc6\u7801"},"content":{"rendered":"<blockquote><p>\n  \u627e\u56de mysql \u5bc6\u7801\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u89e3\u51b3\uff1a\u4f7f\u7528\u6839\u7528\u6237\u91cd\u7f6e\u5bc6\u7801\u6216\u4f7f\u7528 mysqldump \u5bfc\u51fa\u6570\u636e\u5e93\u3002\u521b\u5efa\u65b0\u6570\u636e\u5e93\uff0c\u5bfc\u5165\u6570\u636e\u5e76\u521b\u5efa\u65b0\u7528\u6237\u3002\u6388\u4e88\u6743\u9650\u5e76\u5220\u9664\u65e7\u7528\u6237\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/14\/2024061403452667908.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u627e\u56demysql\u5bc6\u7801\u63d2\u56fe\" alt=\"\u5982\u4f55\u627e\u56demysql\u5bc6\u7801\u63d2\u56fe\" \/><\/p>\n<p><strong>\u627e\u56de MySQL \u5bc6\u7801<\/strong><\/p>\n<p>\u5fd8\u8bb0 MySQL \u5bc6\u7801\u53ef\u80fd\u662f\u4e00\u4e2a\u4ee4\u4eba\u6cae\u4e27\u7684\u60c5\u51b5\uff0c\u4f46\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u8f7b\u677e\u627e\u56de\uff1a<\/p>\n<p><strong>1. \u91cd\u7f6e\u5bc6\u7801<\/strong><\/p>\n<p>\u4f7f\u7528 root \u7528\u6237\u767b\u5f55\u7cfb\u7edf\uff0c\u7136\u540e\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>mysqladmin -u root password '\u65b0\u5bc6\u7801'<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5c06 &#8216;\u65b0\u5bc6\u7801&#8217; \u66ff\u6362\u4e3a\u60a8\u60f3\u8981\u8bbe\u7f6e\u7684\u65b0\u5bc6\u7801\u3002<\/p>\n<p><strong>2. \u4f7f\u7528 dump \u5bfc\u51fa\u6570\u636e\u5e93<\/strong><\/p>\n<p>\u5982\u679c\u60a8\u65e0\u6cd5\u4f7f\u7528 root \u7528\u6237\u91cd\u7f6e\u5bc6\u7801\uff0c\u53ef\u4ee5\u4f7f\u7528 mysqldump \u5de5\u5177\u5bfc\u51fa\u6570\u636e\u5e93\uff1a<\/p>\n<pre>mysqldump --user=\u7528\u6237\u540d --password=\u65e7\u5bc6\u7801 --databases \u6570\u636e\u5e93\u540d &gt; \u5907\u4efd.sql<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5c06 &#8216;\u7528\u6237\u540d&#8217; \u548c &#8216;\u65e7\u5bc6\u7801&#8217; \u66ff\u6362\u4e3a\u73b0\u6709\u7528\u6237\u548c\u5bc6\u7801\u3002<\/p>\n<p><strong>3. \u521b\u5efa\u65b0\u6570\u636e\u5e93<\/strong><\/p>\n<p>\u4f7f\u7528 root \u7528\u6237\u521b\u5efa\u5177\u6709\u76f8\u540c\u540d\u79f0\u7684\u65b0\u6570\u636e\u5e93\uff1a<\/p>\n<pre>CREATE DATABASE \u6570\u636e\u5e93\u540d;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u5bfc\u5165\u6570\u636e<\/strong><\/p>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4ece\u5907\u4efd\u5bfc\u5165\u6570\u636e\uff1a<\/p>\n<pre>mysql -u root \u6570\u636e\u5e93\u540d &lt; \u5907\u4efd.sql<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u521b\u5efa\u65b0\u7528\u6237<\/strong><\/p>\n<p>\u5728\u521b\u5efa\u7684\u65b0\u6570\u636e\u5e93\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7528\u6237\uff1a<\/p>\n<pre>CREATE USER '\u65b0\u7528\u6237\u540d' IDENTIFIED BY '\u65b0\u5bc6\u7801';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>6. \u6388\u4e88\u6743\u9650<\/strong><\/p>\n<p>\u6388\u4e88\u65b0\u7528\u6237\u5bf9\u65b0\u6570\u636e\u5e93\u7684\u6743\u9650\uff1a<\/p>\n<pre>GRANT ALL PRIVILEGES ON \u6570\u636e\u5e93\u540d.* TO '\u65b0\u7528\u6237\u540d';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>7. \u5220\u9664\u65e7\u7528\u6237<\/strong><\/p>\n<p>\u5220\u9664\u65e7\u7528\u6237\uff08\u5982\u679c\u4e0d\u9700\u8981\uff09\uff1a<\/p>\n<pre>DROP USER '\u65e7\u7528\u6237\u540d';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u627e\u56de\u5bc6\u7801\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>\u627e\u56de mysql \u5bc6\u7801\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u89e3\u51b3\uff1a\u4f7f\u7528\u6839\u7528\u6237\u91cd\u7f6e\u5bc6\u7801\u6216\u4f7f\u7528 mysqldump \u5bfc\u51fa\u6570\u636e\u5e93\u3002\u521b\u5efa\u65b0\u6570\u636e\u5e93\uff0c\u5bfc\u5165\u6570\u636e\u5e76\u521b\u5efa\u65b0\u7528\u6237\u3002\u6388\u4e88\u6743\u9650\u5e76\u5220\u9664\u65e7\u7528\u6237\u3002 \u627e\u56de MySQL \u5bc6\u7801 \u5fd8\u8bb0 MySQL \u5bc6\u7801\u53ef\u80fd\u662f\u4e00\u4e2a\u4ee4\u4eba\u6cae\u4e27\u7684\u60c5\u51b5\uff0c\u4f46\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u8f7b\u677e\u627e\u56de\uff1a 1. \u91cd\u7f6e\u5bc6\u7801 \u4f7f\u7528 root \u7528\u6237\u767b\u5f55\u7cfb\u7edf\uff0c\u7136\u540e\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a mysqladmin -u root password &#8216;\u65b0\u5bc6\u7801&#8217; \u767b\u5f55\u540e\u590d\u5236 \u5c06 &#8216;\u65b0\u5bc6\u7801&#8217; \u66ff\u6362\u4e3a\u60a8\u60f3\u8981\u8bbe\u7f6e\u7684\u65b0\u5bc6\u7801\u3002 2. \u4f7f\u7528 dump \u5bfc\u51fa\u6570\u636e\u5e93 \u5982\u679c\u60a8\u65e0\u6cd5\u4f7f\u7528 root \u7528\u6237\u91cd\u7f6e\u5bc6\u7801\uff0c\u53ef\u4ee5\u4f7f\u7528 mysqldump \u5de5\u5177\u5bfc\u51fa\u6570\u636e\u5e93\uff1a mysqldump &#8211;user=\u7528\u6237\u540d &#8211;password=\u65e7\u5bc6\u7801 &#8211;databases \u6570\u636e\u5e93\u540d &gt; \u5907\u4efd.sql \u767b\u5f55\u540e\u590d\u5236 \u5c06 &#8216;\u7528\u6237\u540d&#8217; \u548c &#8216;\u65e7\u5bc6\u7801&#8217; \u66ff\u6362\u4e3a\u73b0\u6709\u7528\u6237\u548c\u5bc6\u7801\u3002 3. \u521b\u5efa\u65b0\u6570\u636e\u5e93 \u4f7f\u7528 root \u7528\u6237\u521b\u5efa\u5177\u6709\u76f8\u540c\u540d\u79f0\u7684\u65b0\u6570\u636e\u5e93\uff1a CREATE DATABASE \u6570\u636e\u5e93\u540d; [&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-6163","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6163","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=6163"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6163\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}