{"id":471,"date":"2010-07-05T10:07:42","date_gmt":"2010-07-05T10:07:42","guid":{"rendered":""},"modified":"2010-07-05T10:07:42","modified_gmt":"2010-07-05T10:07:42","slug":"471","status":"publish","type":"post","link":"https:\/\/www.poloo.org\/?p=471","title":{"rendered":"\u627e\u56deMySQL root\u5bc6\u7801\u7684\u89e3\u51b3\u65b9\u6848"},"content":{"rendered":"<p>\u56e0\u4e3aMySQL\u5bc6\u7801\u5b58\u50a8\u4e8e\u6570\u636e\u5e93MySQL\u4e2d\u7684user\u8868\u4e2d\u6240\u4ee5\u53ea\u9700\u8981\u5c06\u6211windows 2003\u4e0b\u7684MySQL\u4e2d\u7684user\u8868\u62f7\u8d1d\u8fc7\u6765\u8986\u76d6\u6389\u5c31\u884c\u4e86<\/p>\n<p>\u5728c:MySQLdataMySQL(linux \u5219\u4e00\u822c\u5728\/var\/lib\/MySQL\/MySQL\/)\u76ee\u5f55\u4e0b\u6709\u4e09\u4e2auser\u8868\u76f8\u5173\u6587\u4ef6user.frm\u3001user.MYD\u3001user.MYI<\/p>\n<p>user.frm \/\/user\u8868\u6837\u5f0f\u6587\u4ef6<\/p>\n<p>user.MYD \/\/user\u8868\u6570\u636e\u6587\u4ef6<\/p>\n<p>user.MYI \/\/user\u8868\u7d22\u5f15\u6587\u4ef6<\/p>\n<p>\u4e3a\u4fdd\u9669\u8d77\u89c1\uff0c\u4e09\u4e2a\u90fd\u62f7\u8d1d\u8fc7\u6765\uff0c\u4e0d\u8fc7\u5176\u5b9e\u5982\u679c\u4e4b\u524d\u5728\u8981\u6062\u590d\u7684\u90a3\u4e2aMySQL\u4e0a\u6ca1\u6709\u66f4\u6539\u8fc7\u8868\u7ed3\u6784\u7684\u8bdd\uff0c\u53ea\u8981\u62f7\u8d1duser.MYD\u5c31\u884c\u4e86<\/p>\n<p>\u7136\u540e<\/p>\n<p><code><br \/>#. \/etc\/rc.d\/init.d\/MySQL stop&nbsp;&nbsp;<br \/>#. \/etc\/rc.d\/init.d\/MySQL start&nbsp;&nbsp;<br \/>#MySQL -u root -p XXXXXX <br \/><\/code><\/p>\n<p>\u597d\u4e86\uff0c\u53ef\u4ee5\u7528windows 2003\u4e0bMySQL\u5bc6\u7801\u767b\u9646\u4e86<\/p>\n<p><code><br \/>MySQL&gt;use MySQL&nbsp;&nbsp;<br \/>MySQL&gt;update user set Password=PASSWORD('xxxxxx') where User='root'; <br \/><\/code><\/p>\n<p>\u8fd9\u65f6\u5019\u4f1a\u51fa\u9519\uff0c\u63d0\u793auser\u8868\u53ea\u6709\u8bfb\u6743\u9650<\/p>\n<p>\u6211\u5206\u6790\u4e86\u4e00\u4e0b\u539f\u56e0\uff0c\u53ea\u8fd9\u6837\u7684\uff0c\u56e0\u4e3auser.*\u6587\u4ef6\u7684\u6743\u9650\u5206\u914d\u662fwindows 2003\u4e0b\u7684\uff0c\u5728windows 2003\u4e0b\u6211ls -l\u4e00\u770b\u6743\u9650\u662f666<\/p>\n<p>\u5728linux\u4e0b\u6211\u4e00\u770b\uff0c\u62f7\u8fc7\u6765\u540e\u6743\u9650\u53d8\u6210\u4e86600(\u5176\u5b9e\u6b63\u5e38\u60c5\u51b5\u4e0b600\u5c31\u884c\u4e86\uff0c\u53ea\u4e0d\u8fc7\u8fd9\u91cc\u7684\u6587\u4ef6\u5c5e\u4e3b\u4e0d\u662fMySQL\uff0c\u62f7\u8fc7\u6765\u540e\u7684\u5c5e\u4e3b\u53d8\u4e3a\u4e86MySQL root,\u6240\u4ee5\u4f1a\u51fa\u73b0\u6743\u9650\u4e0d\u591f\uff0c\u8fd9\u65f6\u5019\u5982\u679c\u4f60\u6539\u6210\u6743\u9650666\u5219\u53ef\u4ee5\u4e86\uff0c\u5f53\u7136\u8fd9\u6837\u4e0d\u597d\uff0c\u6ca1\u6709\u89e3\u51b3\u95ee\u9898\u7684\u5b9e\u8d28)\uff0c\u5728\/var\/lib\/MySQL\/MySQL\/\u4e0bls -l\u770b\u4e86\u4e00\u4e0b<\/p>\n<p>\u518d<\/p>\n<p><code><br \/>#chown -R MySQL:MySQL user.*&nbsp;&nbsp;<br \/>#chmod 600 user.*&nbsp;&nbsp;<br \/>\/\/OK,DONE <br \/><\/code><\/p>\n<p>\u91cd\u8d77\u4e00\u4e0bMySQL<\/p>\n<p>\u91cd\u65b0\u8fde\u63a5<br \/><code><br \/>MySQL&gt;use MySQL&nbsp;&nbsp;<br \/>MySQL&gt;update user set Password=PASSWORD('xxxxxx') where User='root';&nbsp;&nbsp;<br \/>MySQL&gt;FLUSH PRIVILEGES; <br \/><\/code><\/p>\n<p>\u6709\u4e00\u70b9\u503c\u5f97\u6ce8\u610f:\u5982\u679c\u4f60windows \u4e0bMySQL\u5982\u679c\u662f\u9ed8\u8ba4\u914d\u7f6e\u7684\u8bdd\uff0c\u6ce8\u610f\u8981\u8fd8\u8981\u6267\u884c<br \/><code><br \/>MySQL&gt;delete from user where User='';&nbsp;&nbsp;<br \/>MySQL&gt;delete from user where Host='%';&nbsp;&nbsp;<br \/>MySQL&gt;FLUSH PRIVILEGES;<br \/><\/code><\/p>\n<p>\u597d\u4e86\uff0c\u5230\u8fd9\u91cc\u6062\u590d\u5bc6\u7801\u8fc7\u7a0b\u5c31\u5b8c\u6210\u4e86<\/p>\n<p>\u8fd9\u4e2a\u65b9\u6cd5\u4e48\u5c31\u662f\u6709\u70b9\u5c40\u9650\u6027\uff0c\u4f60\u5fc5\u987b\u4e5f\u5177\u5907\u53e6\u5916\u7684user\u8868\u6587\u4ef6<\/p>\n<p>\u5176\u4ed6\u8fd8\u6709\u51e0\u79cd\u65b9\u6cd5<\/p>\n<p>\u5176\u5b83\u65b9\u6cd5\u4e00(\u8fd9\u4e2a\u662f\u7f51\u4e0a\u6d41\u4f20\u8f83\u5e7f\u7684\u65b9\u6cd5,MySQL\u4e2d\u6587\u53c2\u8003\u624b\u518c\u4e0a\u7684)<\/p>\n<p>1. \u5411MySQLd server \u53d1\u9001kill\u547d\u4ee4\u5173\u6389MySQLd server(\u4e0d\u662f kill -9),\u5b58\u653e\u8fdb\u7a0bID\u7684\u6587\u4ef6\u901a\u5e38\u5728MySQL\u7684\u6570\u636e\u5e93\u6240\u5728\u7684\u76ee\u5f55\u4e2d\u3002<\/p>\n<p>killall -TERM MySQLd<\/p>\n<p>\u4f60\u5fc5\u987b\u662fUNIX\u7684MySQL root\u7528\u6237\u6216\u8005\u662f\u4f60\u6240\u8fd0\u884c\u7684SERVER\u4e0a\u7684\u540c\u7b49\u7528\u6237\uff0c\u624d\u80fd\u6267\u884c\u8fd9\u4e2a\u64cd\u4f5c\u3002<\/p>\n<p>2. \u4f7f\u7528`&#8211;skip-grant-tables&#8217; \u53c2\u6570\u6765\u542f\u52a8 MySQLd\u3002 (LINUX\u4e0b\/usr\/bin\/safe_MySQLd &#8211;skip-grant-tables , windows\u4e0bc:MySQL\binMySQLd &#8211;skip-grant-tables)<\/p>\n<p>3. \u7136\u540e\u65e0\u5bc6\u7801\u767b\u5f55\u5230MySQLd server \uff0c<br \/><code><br \/>&gt;use MySQL&nbsp;&nbsp;<br \/>&gt;update user set passwordpassword=password(\"new_pass\") where user=\"root\";&nbsp;&nbsp;<br \/>&gt;flush privileges; <br \/><\/code><\/p>\n<p>\u4f60\u4e5f\u53ef\u4ee5\u8fd9\u6837\u505a\uff1a<br \/><code><br \/>`MySQLadmin -h hostname -u user password 'new password''\u3002 <br \/><\/code><\/p>\n<p>4. \u8f7d\u5165\u6743\u9650\u8868\uff1a `MySQLadmin -h hostname flush-privileges&#8217; \uff0c\u6216\u8005\u4f7f\u7528 SQL \u547d\u4ee4`FLUSH PRIVILEGES&#8217;\u3002<\/p>\n<p>5.killall -TERM MySQLd<\/p>\n<p>6.\u7528\u65b0\u5bc6\u7801\u767b\u9646<\/p>\n<p>\u5176\u5b83\u65b9\u6cd5\u4e8c<\/p>\n<p>\u76f4\u63a5\u7528\u5341\u516d\u8fdb\u5236\u7f16\u8f91\u5668\u7f16\u8f91user.MYD\u6587\u4ef6<\/p>\n<p>\u4e0d\u8fc7\u8fd9\u4e2a\u91cc\u9762\u6211\u8981\u8bf4\u660e\u4e00\u70b9\uff0c\u6211\u8fd9\u91cc\u7f16\u8f91\u7684\u65f6\u5019\u53d1\u73b0\u4e2a\u95ee\u9898\uff0c\u52a0\u5bc6\u7684\u5bc6\u7801\u4e32\u6709\u4e9b\u662f\u8fde\u7eed\u5b58\u50a8\u7684\uff0c\u6709\u4e9b\u7684\u6700\u540e\u4e24\u4f4d\u88ab\u5207\u5f00\u4e86\uff0c\u540e\u4e24\u4f4d\u5b58\u50a8\u5728\u540e\u9762\u5176\u4ed6\u5730\u65b9.\u8fd9\u4e00\u70b9\u6211\u8fd8\u6ca1\u60f3\u660e\u767d.\u8fd8\u6709\u6ce8\u610f\u4e00\u70b9\u5c31\u662f\u7f16\u8f91\u7684\u662f\u52a0\u5bc6\u8fc7\u7684\u5bc6\u7801\u4e32\uff0c\u4e5f\u5c31\u662f\u8bf4\u4f60\u8fd8\u662f\u9700\u8981\u53e6\u5916\u6709user\u8868\u6587\u4ef6\u3002\u8fd9\u79cd\u65b9\u6cd5\u548c\u6211\u6700\u4e0a\u9762\u4ecb\u7ecd\u7684\u65b9\u6cd5\u7684\u533a\u522b\u5728\u4e8e\uff0c\u8fd9\u79cd\u65b9\u6cd5\u76f4\u63a5\u7f16\u8f91linux\u4e0b\u7684user\u8868\u6587\u4ef6\uff0c\u5c31\u4e0d\u9700\u8981\u91cd\u65b0\u6539\u6587\u4ef6\u5c5e\u4e3b\u548c\u6743\u9650\u4e86<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u56e0\u4e3aMySQL\u5bc6\u7801\u5b58\u50a8\u4e8e\u6570\u636e\u5e93MySQL\u4e2d\u7684user\u8868\u4e2d\u6240\u4ee5\u53ea\u9700\u8981\u5c06&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-471","post","type-post","status-publish","format-standard","hentry","category-DB"],"_links":{"self":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/471","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=471"}],"version-history":[{"count":0,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/471\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}