 {"id":602,"date":"2013-02-05T10:50:16","date_gmt":"2013-02-05T02:50:16","guid":{"rendered":"http:\/\/www.qyuef.com\/?p=602"},"modified":"2013-02-05T10:50:16","modified_gmt":"2013-02-05T02:50:16","slug":"mysql%e5%b8%b8%e7%94%a8%e5%91%bd%e4%bb%a4%e5%a4%a7%e5%85%a8%e9%9b%86%e9%94%a6","status":"publish","type":"post","link":"http:\/\/www.qyuef.com\/?p=602","title":{"rendered":"MySql\u5e38\u7528\u547d\u4ee4\u5927\u5168\u96c6\u9526"},"content":{"rendered":"<p>\n\t<span class=\"top11\">1:\u4f7f\u7528SHOW\u8bed\u53e5\u627e\u51fa\u5728\u670d\u52a1\u5668\u4e0a\u5f53\u524d\u5b58\u5728\u4ec0\u4e48\u6570\u636e\u5e93\uff1a<br \/>\n\tmysql&gt; SHOW DATABASES;<br \/>\n\t2:2\u3001\u521b\u5efa\u4e00\u4e2a\u6570\u636e\u5e93MYSQLDATA<br \/>\n\tmysql&gt; CREATE DATABASE MYSQLDATA;<br \/>\n\t3:\u9009\u62e9\u4f60\u6240\u521b\u5efa\u7684\u6570\u636e\u5e93<br \/>\n\tmysql&gt; USE MYSQLDATA; (\u6309\u56de\u8f66\u952e\u51fa\u73b0Database changed \u65f6\u8bf4\u660e\u64cd\u4f5c\u6210\u529f\uff01)<br \/>\n\t4:\u67e5\u770b\u73b0\u5728\u7684\u6570\u636e\u5e93\u4e2d\u5b58\u5728\u4ec0\u4e48\u8868<br \/>\n\tmysql&gt; SHOW TABLES;<br \/>\n\t5:\u521b\u5efa\u4e00\u4e2a\u6570\u636e\u5e93\u8868<br \/>\n\tmysql&gt; CREATE TABLE MYTABLE (name VARCHAR(20), sex CHAR(1));<br \/>\n\t6:\u663e\u793a\u8868\u7684\u7ed3\u6784\uff1a<br \/>\n\tmysql&gt; DESCRIBE MYTABLE;<br \/>\n\t7:\u5f80\u8868\u4e2d\u52a0\u5165\u8bb0\u5f55<br \/>\n\tmysql&gt; insert into MYTABLE values (&rdquo;hyq&rdquo;,&rdquo;M&rdquo;);<br \/>\n\t8:\u7528\u6587\u672c\u65b9\u5f0f\u5c06\u6570\u636e\u88c5\u5165\u6570\u636e\u5e93\u8868\u4e2d\uff08\u4f8b\u5982D:\/mysql.txt\uff09<br \/>\n\tmysql&gt; LOAD DATA LOCAL INFILE &ldquo;D:\/mysql.txt&rdquo; INTO TABLE MYTABLE;<br \/>\n\t9:\u5bfc\u5165.sql\u6587\u4ef6\u547d\u4ee4\uff08\u4f8b\u5982D:\/mysql.sql\uff09<br \/>\n\tmysql&gt;use database;<br \/>\n\tmysql&gt;source d:\/mysql.sql;<br \/>\n\t10:\u5220\u9664\u8868<br \/>\n\tmysql&gt;drop TABLE MYTABLE;<br \/>\n\t11:\u6e05\u7a7a\u8868<br \/>\n\tmysql&gt;delete from MYTABLE;<br \/>\n\t12:\u66f4\u65b0\u8868\u4e2d\u6570\u636e<br \/>\n\tmysql&gt;update MYTABLE set sex=&rdquo;f&rdquo; where name=&rsquo;hyq&rsquo;;<\/span><\/p>\n<p>\n\t<span class=\"top11\">\u4ee5\u4e0b\u662f\u65e0\u610f\u4e2d\u5728\u7f51\u7edc\u770b\u5230\u7684\u4f7f\u7528MySql\u7684\u7ba1\u7406\u5fc3\u5f97,<br \/>\n\t\u5728windows\u4e2dMySql\u4ee5\u670d\u52a1\u5f62\u5f0f\u5b58\u5728\uff0c\u5728\u4f7f\u7528\u524d\u5e94\u786e\u4fdd\u6b64\u670d\u52a1\u5df2\u7ecf\u542f\u52a8\uff0c\u672a\u542f\u52a8\u53ef\u7528net start mysql\u547d\u4ee4\u542f\u52a8\u3002\u800cLinux\u4e2d\u542f\u52a8\u65f6\u53ef\u7528&ldquo;\/etc\/rc.d\/init.d\/mysqld start&rdquo;\u547d\u4ee4\uff0c\u6ce8\u610f\u542f\u52a8\u8005\u5e94\u5177\u6709\u7ba1\u7406\u5458\u6743\u9650\u3002<br \/>\n\t\u521a\u5b89\u88c5\u597d\u7684MySql\u5305\u542b\u4e00\u4e2a\u542b\u7a7a\u5bc6\u7801\u7684root\u5e10\u6237\u548c\u4e00\u4e2a\u533f\u540d\u5e10\u6237\uff0c\u8fd9\u662f\u5f88\u5927\u7684\u5b89\u5168\u9690\u60a3\uff0c\u5bf9\u4e8e\u4e00\u4e9b\u91cd\u8981\u7684\u5e94\u7528\u6211\u4eec\u5e94\u5c06\u5b89\u5168\u6027\u5c3d\u53ef\u80fd\u63d0\u9ad8\uff0c\u5728\u8fd9\u91cc\u5e94\u628a\u533f\u540d\u5e10\u6237\u5220\u9664\u3001 root\u5e10\u6237\u8bbe\u7f6e\u5bc6\u7801\uff0c\u53ef\u7528\u5982\u4e0b\u547d\u4ee4\u8fdb\u884c\uff1a<br \/>\n\tuse mysql;<br \/>\n\tdelete from User where User=&rdquo;&quot;;<br \/>\n\tupdate User set Password=PASSWORD(&rsquo;newpassword&rsquo;) where User=&rsquo;root&rsquo;;<br \/>\n\t\u5982\u679c\u8981\u5bf9\u7528\u6237\u6240\u7528\u7684\u767b\u5f55\u7ec8\u7aef\u8fdb\u884c\u9650\u5236\uff0c\u53ef\u4ee5\u66f4\u65b0User\u8868\u4e2d\u76f8\u5e94\u7528\u6237\u7684Host\u5b57\u6bb5\uff0c\u5728\u8fdb\u884c\u4e86\u4ee5\u4e0a\u66f4\u6539\u540e\u5e94\u91cd\u65b0\u542f\u52a8\u6570\u636e\u5e93\u670d\u52a1\uff0c\u6b64\u65f6\u767b\u5f55\u65f6\u53ef\u7528\u5982\u4e0b\u7c7b\u4f3c\u547d\u4ee4\uff1a<br \/>\n\tmysql -uroot -p;<br \/>\n\tmysql -uroot -pnewpassword;<br \/>\n\tmysql mydb -uroot -p;<br \/>\n\tmysql mydb -uroot -pnewpassword;<br \/>\n\t\u4e0a\u9762\u547d\u4ee4\u53c2\u6570\u662f\u5e38\u7528\u53c2\u6570\u7684\u4e00\u90e8\u5206\uff0c\u8be6\u7ec6\u60c5\u51b5\u53ef\u53c2\u8003\u6587\u6863\u3002\u6b64\u5904\u7684mydb\u662f\u8981\u767b\u5f55\u7684\u6570\u636e\u5e93\u7684\u540d\u79f0\u3002<br \/>\n\t\u5728 \u8fdb\u884c\u5f00\u53d1\u548c\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u7528\u6237\u4e0d\u5e94\u8be5\u53ea\u7528root\u7528\u6237\u8fdb\u884c\u8fde\u63a5\u6570\u636e\u5e93\uff0c\u867d\u7136\u4f7f\u7528root\u7528\u6237\u8fdb\u884c\u6d4b\u8bd5\u65f6\u5f88\u65b9\u4fbf\uff0c\u4f46\u4f1a\u7ed9\u7cfb\u7edf\u5e26\u6765\u91cd\u5927\u5b89\u5168\u9690\u60a3\uff0c\u4e5f\u4e0d\u5229\u4e8e\u7ba1\u7406\u6280 \u672f\u7684\u63d0\u9ad8\u3002\u6211\u4eec\u7ed9\u4e00\u4e2a\u5e94\u7528\u4e2d\u4f7f\u7528\u7684\u7528\u6237\u8d4b\u4e88\u6700\u6070\u5f53\u7684\u6570\u636e\u5e93\u6743\u9650\u3002\u5982\u4e00\u4e2a\u53ea\u8fdb\u884c\u6570\u636e\u63d2\u5165\u7684\u7528\u6237\u4e0d\u5e94\u8d4b\u4e88\u5176\u5220\u9664\u6570\u636e\u7684\u6743\u9650\u3002MySql\u7684\u7528\u6237\u7ba1\u7406\u662f\u901a\u8fc7 User\u8868\u6765\u5b9e\u73b0\u7684\uff0c\u6dfb\u52a0\u65b0\u7528\u6237\u5e38\u7528\u7684\u65b9\u6cd5\u6709\u4e24\u4e2a\uff0c\u4e00\u662f\u5728User\u8868\u63d2\u5165\u76f8\u5e94\u7684\u6570\u636e\u884c\uff0c\u540c\u65f6\u8bbe\u7f6e\u76f8\u5e94\u7684\u6743\u9650\uff1b\u4e8c\u662f\u901a\u8fc7GRANT\u547d\u4ee4\u521b\u5efa\u5177\u6709\u67d0\u79cd\u6743\u9650\u7684\u7528 \u6237\u3002\u5176\u4e2dGRANT\u7684\u5e38\u7528\u7528\u6cd5\u5982\u4e0b\uff1a<br \/>\n\tgrant all on mydb.* to NewUserName@HostName identified by &ldquo;password&rdquo; ;<br \/>\n\tgrant usage on *.* to NewUserName@HostName identified by &ldquo;password&rdquo;;<br \/>\n\tgrant select,insert,update on mydb.* to NewUserName@HostName identified by &ldquo;password&rdquo;;<br \/>\n\tgrant update,delete on mydb.TestTable to NewUserName@HostName identified by &ldquo;password&rdquo;;<br \/>\n\t\u82e5 \u8981\u7ed9\u6b64\u7528\u6237\u8d4b\u4e88\u4ed6\u5728\u76f8\u5e94\u5bf9\u8c61\u4e0a\u7684\u6743\u9650\u7684\u7ba1\u7406\u80fd\u529b\uff0c\u53ef\u5728GRANT\u540e\u9762\u6dfb\u52a0WITH GRANT OPTION\u9009\u9879\u3002\u800c\u5bf9\u4e8e\u7528\u63d2\u5165User\u8868\u6dfb\u52a0\u7684\u7528\u6237\uff0cPassword\u5b57\u6bb5\u5e94\u7528PASSWORD \u51fd\u6570\u8fdb\u884c\u66f4\u65b0\u52a0\u5bc6\uff0c\u4ee5\u9632\u4e0d\u8f68\u4e4b\u4eba\u7a83\u770b\u5bc6\u7801\u3002\u5bf9\u4e8e\u90a3\u4e9b\u5df2\u7ecf\u4e0d\u7528\u7684\u7528\u6237\u5e94\u7ed9\u4e88\u6e05\u9664\uff0c\u6743\u9650\u8fc7\u754c\u7684\u7528\u6237\u5e94\u53ca\u65f6\u56de\u6536\u6743\u9650\uff0c\u56de\u6536\u6743\u9650\u53ef\u4ee5\u901a\u8fc7\u66f4\u65b0User\u8868\u76f8\u5e94\u5b57\u6bb5\uff0c \u4e5f\u53ef\u4ee5\u4f7f\u7528REVOKE\u64cd\u4f5c\u3002<br \/>\n\t\u4e0b\u9762\u7ed9\u51fa\u672c\u4eba\u4ece\u5176\u5b83\u8d44\u6599(www.cn-java.com)\u83b7\u5f97\u7684\u5bf9\u5e38\u7528\u6743\u9650\u7684\u89e3\u91ca\uff1a<br \/>\n\t\u5168\u5c40\u7ba1\u7406\u6743\u9650\uff1a<br \/>\n\tFILE: \u5728MySQL\u670d\u52a1\u5668\u4e0a\u8bfb\u5199\u6587\u4ef6\u3002<br \/>\n\tPROCESS: \u663e\u793a\u6216\u6740\u6b7b\u5c5e\u4e8e\u5176\u5b83\u7528\u6237\u7684\u670d\u52a1\u7ebf\u7a0b\u3002<br \/>\n\tRELOAD: \u91cd\u8f7d\u8bbf\u95ee\u63a7\u5236\u8868\uff0c\u5237\u65b0\u65e5\u5fd7\u7b49\u3002<br \/>\n\tSHUTDOWN: \u5173\u95edMySQL\u670d\u52a1\u3002<br \/>\n\t\u6570\u636e\u5e93\/\u6570\u636e\u8868\/\u6570\u636e\u5217\u6743\u9650\uff1a<br \/>\n\tALTER: \u4fee\u6539\u5df2\u5b58\u5728\u7684\u6570\u636e\u8868(\u4f8b\u5982\u589e\u52a0\/\u5220\u9664\u5217)\u548c\u7d22\u5f15\u3002<br \/>\n\tCREATE: \u5efa\u7acb\u65b0\u7684\u6570\u636e\u5e93\u6216\u6570\u636e\u8868\u3002<br \/>\n\tDELETE: \u5220\u9664\u8868\u7684\u8bb0\u5f55\u3002<br \/>\n\tDROP: \u5220\u9664\u6570\u636e\u8868\u6216\u6570\u636e\u5e93\u3002<br \/>\n\tINDEX: \u5efa\u7acb\u6216\u5220\u9664\u7d22\u5f15\u3002<br \/>\n\tINSERT: \u589e\u52a0\u8868\u7684\u8bb0\u5f55\u3002<br \/>\n\tSELECT: \u663e\u793a\/\u641c\u7d22\u8868\u7684\u8bb0\u5f55\u3002<br \/>\n\tUPDATE: \u4fee\u6539\u8868\u4e2d\u5df2\u5b58\u5728\u7684\u8bb0\u5f55\u3002<br \/>\n\t\u7279\u522b\u7684\u6743\u9650\uff1a<br \/>\n\tALL: \u5141\u8bb8\u505a\u4efb\u4f55\u4e8b(\u548croot\u4e00\u6837)\u3002<br \/>\n\tUSAGE: \u53ea\u5141\u8bb8\u767b\u5f55&ndash;\u5176\u5b83\u4ec0\u4e48\u4e5f\u4e0d\u5141\u8bb8\u505a\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728windows\u4e2dMySql\u4ee5\u670d\u52a1\u5f62\u5f0f\u5b58\u5728\uff0c\u5728\u4f7f\u7528\u524d\u5e94\u786e\u4fdd\u6b64\u670d\u52a1\u5df2\u7ecf\u542f\u52a8\uff0c\u672a\u542f\u52a8\u53ef\u7528net start mysql\u547d\u4ee4\u542f\u52a8\u3002\u800cLinux\u4e2d\u542f\u52a8\u65f6\u53ef\u7528\u201c\/etc\/rc.d\/init.d\/mysqld start\u201d\u547d\u4ee4\uff0c\u6ce8\u610f\u542f\u52a8\u8005\u5e94\u5177\u6709\u7ba1\u7406\u5458\u6743\u9650\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[],"tcat":[],"_links":{"self":[{"href":"http:\/\/www.qyuef.com\/index.php?rest_route=\/wp\/v2\/posts\/602"}],"collection":[{"href":"http:\/\/www.qyuef.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.qyuef.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.qyuef.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.qyuef.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=602"}],"version-history":[{"count":0,"href":"http:\/\/www.qyuef.com\/index.php?rest_route=\/wp\/v2\/posts\/602\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.qyuef.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.qyuef.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=602"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.qyuef.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=602"},{"taxonomy":"tcat","embeddable":true,"href":"http:\/\/www.qyuef.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftcat&post=602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}