{"id":1309,"date":"2017-01-28T21:22:11","date_gmt":"2017-01-28T13:22:11","guid":{"rendered":"http:\/\/www.royalwzy.com\/?p=1309"},"modified":"2017-01-28T21:30:57","modified_gmt":"2017-01-28T13:30:57","slug":"mysql-ocp-11-%e7%94%a8%e6%88%b7%e7%ae%a1%e7%90%86","status":"publish","type":"post","link":"http:\/\/www.royalwzy.com\/?p=1309","title":{"rendered":"MySQL OCP-11-\u7528\u6237\u7ba1\u7406"},"content":{"rendered":"<p>&#8212; \u7528\u6237\u7ba1\u7406\u7684\u91cd\u8981\u6027;<br \/>\n\u5728MySQL\u4e2d\u7ba1\u7406\u7528\u6237\u65f6,\u53ef\u4ee5\u63a7\u5236\u5141\u8bb8\u6216\u4e0d\u5141\u8bb8\u7528\u6237\u6267\u884c\u7684\u64cd\u4f5c;<br \/>\n\u2022 \u521b\u5efa\u5177\u6709\u4e0e\u7528\u6237\u7684\u804c\u80fd\u76f8\u5e94\u7684\u4e0d\u540c\u7279\u6743\u7684\u7528\u6237\u5e10\u6237;<br \/>\n\u2022 \u907f\u514d\u4f7f\u7528root\u5e10\u6237:<br \/>\n    \u2013 \u9650\u5236\u53d7\u635f\u5bb3\u7684\u5e94\u7528\u7a0b\u5e8f;<br \/>\n    \u2013 \u9632\u6b62\u5728\u4f8b\u884c\u7ef4\u62a4\u671f\u95f4\u51fa\u9519;<br \/>\n\u2022 \u901a\u8fc7\u6070\u5f53\u8c03\u6574\u5355\u4e2a\u7528\u6237\u7279\u6743\u786e\u4fdd\u6570\u636e\u5b8c\u6574\u6027:<br \/>\n    \u2013 \u5141\u8bb8\u6388\u6743\u7528\u6237\u5b8c\u6210\u5176\u5de5\u4f5c;<br \/>\n    \u2013 \u963b\u6b62\u672a\u7ecf\u6388\u6743\u7528\u6237\u8bbf\u95ee\u8d85\u51fa\u5176\u7279\u6743\u7684\u6570\u636e;<\/p>\n<p>&#8212; \u7528\u6237\u5e10\u6237\u9a8c\u8bc1;<br \/>\n\u5728\u8fde\u63a5\u5230MySQL\u670d\u52a1\u5668\u5e76\u6267\u884c\u67e5\u8be2\u65f6,\u4f1a\u9a8c\u8bc1\u60a8\u7684\u8eab\u4efd\u5e76\u4e3a\u60a8\u7684\u6d3b\u52a8\u6388\u6743;<br \/>\n\u2022 \u9a8c\u8bc1:\u9a8c\u8bc1\u7528\u6237\u7684\u8eab\u4efd;\u8fd9\u662f\u8bbf\u95ee\u63a7\u5236\u7684\u7b2c\u4e00\u4e2a\u9636\u6bb5,\u6bcf\u6b21\u8fde\u63a5\u65f6\u90fd\u5fc5\u987b\u6210\u529f\u9a8c\u8bc1\u8eab\u4efd,\u5982\u679c\u9a8c\u8bc1\u5931\u8d25,\u5219\u65e0\u6cd5\u8fde\u63a5,\u60a8\u7684\u5ba2\u6237\u673a\u5c06\u65ad\u5f00\u8fde\u63a5;<br \/>\n\u2022 \u6388\u6743:\u9a8c\u8bc1\u7528\u6237\u7684\u7279\u6743;\u8fd9\u662f\u8bbf\u95ee\u63a7\u5236\u7684\u7b2c\u4e8c\u4e2a\u9636\u6bb5,\u9762\u5411\u9488\u5bf9\u6210\u529f\u9a8c\u8bc1\u4e86\u8eab\u4efd\u7684\u6d3b\u52a8\u8fde\u63a5\u7684\u6bcf\u4e2a\u8bf7\u6c42;\u5bf9\u4e8e\u6bcf\u4e2a\u8bf7\u6c42,MySQL\u5c06\u786e\u5b9a\u60a8\u8981\u6267\u884c\u7684\u64cd\u4f5c,\u7136\u540e\u68c0\u67e5\u60a8\u662f\u5426\u6709\u6267\u884c\u6b64\u64cd\u4f5c\u6240\u9700\u7684\u6070\u5f53\u7279\u6743;<\/p>\n<p>&#8212; \u67e5\u770b\u7528\u6237\u5e10\u6237\u8bbe\u7f6e;<br \/>\nmysql\u6570\u636e\u5e93\u5305\u542b\u670d\u52a1\u5668\u4e0a\u6240\u6709\u7528\u6237\u5e10\u6237\u7684\u4fe1\u606f:<br \/>\n1.\u67e5\u8be2mysql\u6570\u636e\u5e93\u4ee5\u67e5\u770buser\u6807\u8bc6\u4fe1\u606f:mysql> SELECT user, host, password FROM mysql.user WHERE user=&#8217;root&#8217;;<br \/>\n2.\u67e5\u770b\u5305\u62ec\u7279\u6743\u5728\u5185\u7684\u6240\u6709user\u4fe1\u606f:SELECT * FROM mysql.user\\G<br \/>\n    1.*_priv\u5b57\u6bb5\u4e2d\u7684\u503cY\u8868\u793a\u5df2\u542f\u7528\u76f8\u5e94\u7279\u6743;<br \/>\n    2.root\u5e10\u6237\u5177\u6709\u5b8c\u5168\u8bbf\u95ee\u6743\u9650,\u8be5\u5e10\u6237\u7684\u6240\u6709\u7279\u6743\u5217\u7684\u503c\u5747\u4e3aY;<br \/>\n    3.\u9664\u4e86\u7279\u6743\u4ee5\u5916,\u8be5\u7528\u6237\u8868\u8fd8\u5305\u542b\u5728\u9a8c\u8bc1\u8fc7\u7a0b\u4e2d\u6709\u7528\u7684\u5176\u4ed6\u4fe1\u606f;<br \/>\n    4.Password\u5217\u4e2d\u4ee5\u52a0\u5bc6\u683c\u5f0f\u663e\u793a\u5bc6\u7801;password_expired:\u8868\u793a\u53e3\u4ee4\u662f\u5426\u8fc7\u671f;<br \/>\n    5.max_*:\u8d44\u6e90\u9650\u5236,0\u8868\u793a\u65e0\u9650\u5236;<br \/>\n    6.ssl_*\u548cx509_*:SSL\u6216x509\u8bbe\u7f6e;<br \/>\n    7.plugin:\u5217\u51fa\u4e86\u5bc6\u7801\u63d2\u4ef6\u540d\u79f0(eg:mysql_native_password\u63d2\u4ef6\u9a8c\u8bc1\u8eab\u4efd);<\/p>\n<p>&#8212; \u672c\u673a\u9a8c\u8bc1;<br \/>\n\u2022 \u5728\u4f7f\u7528mysql_native_password\u63d2\u4ef6\u8fde\u63a5\u8fc7\u7a0b\u4e2d,MySQL\u5c06\u4f7f\u7528\u4ee5\u4e0b\u5404\u9879\u4e0emysql.user\u8868\u4e2d\u7684\u884c\u8fdb\u884c\u5339\u914d\u9a8c\u8bc1\u5e10\u6237:<br \/>\n    \u2013 \u7528\u6237\u540d<br \/>\n    \u2013 \u53e3\u4ee4<br \/>\n    \u2013 \u5ba2\u6237\u673a\u4e3b\u673a<br \/>\n\u2022 \u5728\u6307\u5b9a\u4e3b\u673a\u540d\u65f6,\u8981\u6ce8\u610f\u6070\u5f53\u7684\u65b9\u9762:<br \/>\n    \u2013 \u5728\u4f7f\u7528\u5ba2\u6237\u673a\u8fde\u63a5\u65f6\u6307\u5b9a\u670d\u52a1\u5668\u7684\u4e3b\u673a\u540d;<br \/>\n    \u2013 \u5728\u5411\u670d\u52a1\u5668\u6dfb\u52a0\u7528\u6237\u65f6\u6307\u5b9a\u5ba2\u6237\u673a\u7684\u4e3b\u673a\u540d;<br \/>\n\u8865\u5145:<br \/>\n\u8981\u4f7f\u7528mysql\u5ba2\u6237\u673a\u8fde\u63a5\u5230\u672c\u5730\u670d\u52a1\u5668:shell> mysql -u<username> -p<password>\n\u8981\u4f7f\u7528mysql\u5ba2\u6237\u673a\u8fde\u63a5\u5230\u8fdc\u7a0b\u670d\u52a1\u5668:shell> mysql -u<username> -p<password> -h<server_host><\/p>\n<p>&#8212; \u521b\u5efa\u7528\u6237\u5e10\u6237;<br \/>\n1.\u63d0\u4f9b\u6bcf\u4e2a\u7528\u6237\u5e10\u6237\u7684\u7528\u6237\u548c\u4e3b\u673a;<br \/>\n2.\u4f7f\u7528CREATE USER&#8230;IDENTIFIED BY\u8bed\u53e5\u53ef\u4ee5:<br \/>\n    \u2013 \u4e3a\u7528\u6237 jim \u5efa\u7acb\u4e00\u4e2a\u5e10\u6237;<br \/>\n    \u2013 \u8be5\u5e10\u6237\u4ece localhost \u53d1\u51fa\u8fde\u63a5;<br \/>\n    \u2013 \u8be5\u5e10\u6237\u4f7f\u7528\u53e3\u4ee4 Abc123:<br \/>\n    CREATE USER &#8216;jim&#8217;@&#8217;localhost&#8217; IDENTIFIED BY &#8216;Abc123&#8217;;<br \/>\n3.\u5728\u521b\u5efa\u5e10\u6237\u65f6\u907f\u514d\u53ef\u80fd\u7684\u5b89\u5168\u98ce\u9669:<br \/>\n    \u2013 \u4e0d\u521b\u5efa\u6ca1\u6709\u53e3\u4ee4\u7684\u5e10\u6237;<br \/>\n    \u2013 \u4e0d\u521b\u5efa\u533f\u540d\u5e10\u6237;<br \/>\n    \u2013 \u5728\u53ef\u80fd\u7684\u60c5\u51b5\u4e0b,\u907f\u514d\u5728\u6307\u5b9a\u5e10\u6237\u4e3b\u673a\u540d\u65f6\u4f7f\u7528\u901a\u914d\u7b26;<br \/>\n4.\u521b\u5efa\u4e00\u4e2a\u533f\u540d\u8d26\u6237,\u4e0d\u9700\u8981\u7528\u6237\u540d\u548c\u5bc6\u7801\u5373\u53ef\u767b\u5f55,\u6bd4\u8f83\u5371\u9669.eg:insert into user(host, user, password) values(&#8216;%&#8217;, &#8221;, &#8221;);<br \/>\nTIPS:<br \/>\n1.\u5e10\u6237\u540d\u79f0\u7684\u683c\u5f0f\u4e3a&#8217;user_name&#8217;@&#8217;host_name&#8217;;<br \/>\n2.\u7528\u6237\u540d\u957f\u5ea6\u6700\u591a\u53ef\u4ee5\u670916\u4e2a\u5b57\u7b26,\u5982\u679c\u7528\u6237\u540d\u548c\u4e3b\u673a\u540d\u5305\u542b\u7279\u6b8a\u5b57\u7b26(\u5982\u77ed\u5212\u7ebf),\u5219\u5fc5\u987b\u5c06\u5b83\u4eec\u653e\u5728\u5355\u5f15\u53f7\u4e2d;\u5982\u679c\u67d0\u4e2a\u503c\u5728\u4e0d\u5e26\u5f15\u53f7\u65f6\u4e5f\u6709\u6548,\u5219\u5f15\u53f7\u662f\u53ef\u9009\u7684,\u4f46\u662f,\u4efb\u4f55\u60c5\u51b5\u4e0b\u90fd\u53ef\u4f7f\u7528\u5f15\u53f7;<\/p>\n<p>&#8212; \u4e3b\u673a\u540d\u6a21\u5f0f;<br \/>\n1.\u5141\u8bb8\u7684\u4e3b\u673a\u540d\u683c\u5f0f\u793a\u4f8b:<br \/>\n    \u2022 \u4e3b\u673a\u540d:localhost;<br \/>\n    \u2022 \u5408\u683c\u7684\u4e3b\u673a\u540d:&#8217;hostname.example.com&#8217;;<br \/>\n    \u2022 IP\u7f16\u53f7:192.168.9.78;<br \/>\n    \u2022 IP\u5730\u5740:10.0.0.0\/255.255.255.0;<br \/>\n    \u2022 \u6a21\u5f0f\u6216\u901a\u914d\u7b26:%\u6216_;<br \/>\n2.\u4f7f\u7528\u5305\u542b%\u6216_\u901a\u914d\u7b26\u5b57\u7b26\u7684\u4e3b\u673a\u6a21\u5f0f\u8bbe\u7f6e\u7684\u5e10\u6237\u5141\u8bb8\u7528\u6237\u4ece\u6574\u4e2a\u57df\u6216\u5b50\u7f51\u4e2d\u7684\u4efb\u4f55\u4e3b\u673a\u8fde\u63a5;<br \/>\n3.\u7701\u7565\u5e10\u6237\u540d\u79f0\u7684\u4e3b\u673a\u90e8\u5206,MySQL\u5c06\u5047\u5b9a\u4e3b\u673a\u540d\u4e3a%;<br \/>\n    1.\u4e3b\u673a\u503c%.example.com\u53ef\u5339\u914dexample.com\u57df\u4e2d\u7684\u4efb\u4f55\u4e3b\u673a;<br \/>\n    2.\u4e3b\u673a\u503c 192.168.%\u53ef\u5339\u914d192.168\u5b50\u7f51\u4e2d\u7684\u4efb\u4f55\u4e3b\u673a;<br \/>\n    3.\u4e3b\u673a\u503c%\u53ef\u5339\u914d\u4efb\u4f55\u4e3b\u673a,\u5141\u8bb8\u7528\u6237\u4ece\u4efb\u4f55\u4e3b\u673a\u8fde\u63a5;<br \/>\n4.\u7528\u6237\u540d\u548c\u4e3b\u673a\u540d\u793a\u4f8b:<br \/>\n    \u2022 john@10.20.30.40;<br \/>\n    \u2022 john@&#8217;10.20.30.%&#8217;;<br \/>\n    \u2022 john@&#8217;%.ourdomain.com&#8217;;<br \/>\n    \u2022 john@&#8217;10.20.30.0\/255.255.255.0&#8242;;<br \/>\n5.\u6307\u5b9a\u533f\u540d\u7528\u6237\u5e10\u6237(\u5373\u5339\u914d\u4efb\u4f55\u7528\u6237\u540d\u7684\u5e10\u6237):mysql> CREATE USER &#8221;@&#8217;localhost&#8217;;\u8981\u907f\u514d\u521b\u5efa\u533f\u540d\u5e10\u6237,\u5c24\u5176\u662f\u6ca1\u6709\u53e3\u4ee4\u7684\u533f\u540d\u5e10\u6237,\u8fd9\u6709\u52a9\u4e8e\u907f\u514d\u7531\u4e8e\u5f00\u653e\u5bf9MySQL\u5b89\u88c5\u7684\u8bbf\u95ee\u6743\u9650\u5e26\u6765\u7684\u5b89\u5168\u98ce\u9669;<br \/>\n6.\u5982\u679c\u67d0\u4e2a\u4e3b\u673a\u5339\u914d\u4e24\u4e2a\u6216\u66f4\u591a\u6a21\u5f0f,\u5219MySQL\u5c06\u9009\u62e9\u6700\u5177\u4f53\u7684\u6a21\u5f0f;<\/p>\n<p>&#8212; \u8bbe\u7f6e\u5e10\u6237\u53e3\u4ee4;<br \/>\n1.\u8bbe\u7f6eMySQL\u7528\u6237\u53e3\u4ee4\u7684\u65b9\u6cd5\u6709\u591a\u79cd:<br \/>\n    \u2013 CREATE USER&#8230;IDENTIFIED BY:\u81ea\u52a8\u4e3a\u63d0\u4f9b\u7684\u53e3\u4ee4\u52a0\u5bc6;<br \/>\n    \u2013 GRANT&#8230;IDENTIFIED BY<br \/>\n    \u2013 SET PASSWORD<br \/>\n    \u2013 mysqladmin password:shell> mysqladmin -u root password &#8216;rootpass&#8217;;<br \/>\n    \u2013 UPDATE \u6388\u6743\u8868(\u4e0d\u63a8\u8350)<br \/>\n2.SET PASSWORD\u8bed\u53e5\u662f\u8bbe\u7f6e\u6216\u66f4\u6539\u5e10\u6237\u53e3\u4ee4\u7684\u6700\u5e38\u7528\u65b9\u6cd5:<br \/>\n    1.\u66f4\u6539\u73b0\u6709\u5e10\u6237\u7684\u53e3\u4ee4\u4f46\u4e0d\u66f4\u6539\u5176\u4efb\u4f55\u7279\u6743\u7684\u6700\u5e38\u7528\u65b9\u6cd5;<br \/>\n    2.\u8bed\u6cd5:SET PASSWORD FOR &#8216;jim&#8217;@&#8217;localhost&#8217; = PASSWORD(&#8216;NewPass&#8217;);<br \/>\n    3.\u4f7f\u7528SET PASSWORD\u8bed\u53e5\u4f46\u4e0d\u5e26FOR\u5b50\u53e5\u4ec5\u80fd\u66f4\u6539\u60a8\u81ea\u5df1\u7684\u53e3\u4ee4;<\/p>\n<p>&#8212; \u786e\u8ba4\u53e3\u4ee4;<br \/>\n\u4e3a\u6240\u6709\u7528\u6237\u5e10\u6237\u5206\u914d\u552f\u4e00\u7684\u5f3a\u53e3\u4ee4:<br \/>\n\u2022 \u907f\u514d\u53ef\u4ee5\u8f7b\u6613\u731c\u6d4b\u5230\u7684\u53e3\u4ee4;<br \/>\n\u2022 \u4f7f\u7528\u4ee5\u4e0bSELECT\u8bed\u53e5\u53ef\u5217\u51fa\u6ca1\u6709\u53e3\u4ee4\u7684\u6240\u6709\u5e10\u6237:SELECT Host, User FROM mysql.user WHERE Password = &#8221;;<br \/>\n\u2022 \u786e\u5b9a\u91cd\u590d\u53e3\u4ee4:SELECT User FROM mysql.user GROUP BY password HAVING count(user)>1;<br \/>\n\u2022 \u8ba9\u53e3\u4ee4\u5931\u6548:ALTER USER jim@localhost PASSWORD EXPIRE;\u5982\u679c\u5bc6\u7801\u5931\u6548,\u5219\u5728\u4e0b\u6b21\u767b\u5f55\u65f6\u5fc5\u987b\u4f7f\u7528SET PASSWORD\u8bed\u53e5\u66f4\u6539\u53e3\u4ee4;\u6240\u6709\u4e0d\u4ee5SET\u5f00\u5934\u7684\u6267\u884c\u8bed\u53e5\u5c06\u8fd4\u56de\u9519\u8bef,\u76f4\u5230\u66f4\u6539\u53e3\u4ee4\u4e3a\u6b62;<\/p>\n<p>&#8212; \u5904\u7406\u7528\u6237\u5e10\u6237;<br \/>\n\u2022 \u4f7f\u7528RENAME USER\u8bed\u53e5\u53ef\u91cd\u547d\u540d\u7528\u6237\u5e10\u6237:RENAME USER &#8216;jim&#8217;@&#8217;localhost&#8217; TO &#8216;james&#8217;@&#8217;localhost&#8217;;<br \/>\n    \u2013 \u66f4\u6539\u73b0\u6709\u5e10\u6237\u7684\u5e10\u6237\u540d\u79f0<br \/>\n    \u2013 \u66f4\u6539\u5e10\u6237\u540d\u79f0\u7684\u7528\u6237\u540d\u6216\u4e3b\u673a\u540d\u90e8\u5206,\u6216\u540c\u65f6\u66f4\u6539\u4e24\u8005;<br \/>\n\u2022 \u4f7f\u7528DROP USER\u8bed\u53e5\u53ef\u5220\u9664\u7528\u6237\u5e10\u6237:DROP USER &#8216;jim&#8217;@&#8217;localhost&#8217;:<br \/>\n    \u2013 \u64a4\u6d88\u73b0\u6709\u5e10\u6237\u7684\u6240\u6709\u7279\u6743,\u7136\u540e\u5220\u9664\u8be5\u5e10\u6237;<br \/>\n    \u2013 \u4ece\u5b58\u5728\u5e10\u6237\u7684\u4efb\u4f55\u6388\u6743\u8868\u4e2d\u5220\u9664\u5e10\u6237\u7684\u6240\u6709\u8bb0\u5f55;<br \/>\n\u2022 \u5728\u7528\u6237\u8bbf\u95ee\u8981\u6c42\u53d8\u5316\u65f6,\u91cd\u547d\u540d\u6216\u5220\u9664\u7528\u6237;<\/p>\n<p>&#8212; \u53ef\u63d2\u5165\u9a8c\u8bc1;<br \/>\nMySQL\u652f\u6301\u591a\u79cd\u901a\u8fc7\u53ef\u63d2\u5165\u9a8c\u8bc1\u63d0\u4f9b\u7684\u9a8c\u8bc1\u673a\u5236:<br \/>\n1.\u63d2\u4ef6\u662f\u5185\u7f6e\u7684,\u4e5f\u53ef\u4f5c\u4e3a\u5916\u90e8\u5e93\u63d0\u4f9b;<br \/>\n2.\u9ed8\u8ba4\u7684\u670d\u52a1\u5668\u7aef\u63d2\u4ef6\u662f\u5185\u7f6e\u7684,\u59cb\u7ec8\u53ef\u7528,\u5176\u4e2d\u5305\u62ec:<br \/>\n    \u2013 mysql_native_password:\u8fd9\u662f\u9ed8\u8ba4\u673a\u5236,\u63d2\u4ef6\u5b9e\u65bd\u6807\u51c6\u53e3\u4ee4\u683c\u5f0f:41\u5b57\u8282\u5bbd\u7684\u6563\u5217;<br \/>\n    \u2013 mysql_old_password:\u6b64\u63d2\u4ef6\u7684\u5b9e\u73b0\u9a8c\u8bc1\u7684\u65b9\u5f0f\u4e0eMySQL4.1.1\u4e4b\u524d\u7684\u7248\u672c\u76f8\u540c;\u5b89\u5168\u6027\u8f83\u4f4e,16\u5b57\u8282\u5bbd;<br \/>\n    \u2013 sha256_password:\u6b64\u63d2\u4ef6\u53ef\u542f\u7528\u53e3\u4ee4\u7684SHA-256\u6563\u5217;<br \/>\n3.old_passwords\u7cfb\u7edf\u53d8\u91cf\u7684\u503c\u6307\u5b9aPASSWORD()\u51fd\u6570\u7528\u4e8e\u521b\u5efa\u53e3\u4ee4\u7684\u7b97\u6cd5,\u5982\u4e0b\u6240\u793a:<br \/>\n    \u2022 0:\u6807\u51c6\u7b97\u6cd5,\u4e0eMySQL 4.1.1\u53ca\u66f4\u9ad8\u7248\u672c\u4e2d\u6240\u7528\u7684\u7b97\u6cd5\u76f8\u540c;<br \/>\n    \u2022 1:\u65e7\u7b97\u6cd5,\u4e0eMySQL 4.1.1\u4e4b\u524d\u7248\u672c\u4e2d\u6240\u7528\u7684\u7b97\u6cd5\u76f8\u540c;<br \/>\n    \u2022 2:SHA-256\u7b97\u6cd5;<br \/>\n4.\u542f\u52a8\u670d\u52a1\u5668\u65f6\u5c06default-authentication-plugin\u9009\u9879\u8bbe\u7f6e\u4e3asha256_password,\u53ef\u5c06SHA-256\u53e3\u4ee4\u7528\u4e8e\u6240\u6709\u65b0\u7528\u6237,\u4e5f\u53ef\u4f7f\u7528CREATE USER\u548cIDENTIFIED WITH sha256_password\u5b50\u53e5\u4e3a\u7279\u5b9a\u7528\u6237\u6307\u5b9aSHA-256\u53e3\u4ee4;<\/p>\n<p>&#8212; \u5ba2\u6237\u7aef\u660e\u6587\u9a8c\u8bc1\u63d2\u4ef6;<br \/>\nMySQL\u5ba2\u6237\u673a\u5e93\u4e2d\u6709\u4e00\u4e2a\u5185\u7f6e\u7684\u660e\u6587\u9a8c\u8bc1\u63d2\u4ef6mysql_clear_password,\u8be5\u63d2\u4ef6:<br \/>\n1.\u7528\u4e8e\u5c06\u7eaf\u6587\u672c\u53e3\u4ee4\u53d1\u9001\u7ed9\u670d\u52a1\u5668:\u53e3\u4ee4\u901a\u5e38\u7ecf\u8fc7\u6563\u5217\u5904\u7406;<br \/>\n2.\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u542f\u7528:<br \/>\n    \u2013 LIBMYSQL_ENABLE_CLEARTEXT_PLUGIN:\u73af\u5883\u53d8\u91cf;<br \/>\n    \u2013 \u5728\u8fd0\u884cMySQL\u5ba2\u6237\u673a\u5e94\u7528\u7a0b\u5e8f(\u5982mysql\u548cmysqladmin)\u65f6\u6307\u5b9a&#8211;enable-cleartext-plugin;<br \/>\n    \u2013 mysql_options() C API\u51fd\u6570\u7684MYSQL_ENABLE_CLEARTEXT_PLUGIN\u9009\u9879;<br \/>\n3.\u6709\u4e9b\u9a8c\u8bc1\u65b9\u6cd5(\u5982PAM(Pluggable Authentication Module,\u53ef\u63d2\u5165\u9a8c\u8bc1\u6a21\u5757)\u9a8c\u8bc1)\u8981\u6c42\u5ba2\u6237\u673a\u5411\u670d\u52a1\u5668\u53d1\u9001\u7eaf\u6587\u672c\u53e3\u4ee4,\u4ee5\u4fbf\u670d\u52a1\u5668\u5904\u7406\u666e\u901a\u5f62\u5f0f\u7684\u53e3\u4ee4,mysql_clear_password\u63d2\u4ef6\u652f\u6301\u6b64\u884c\u4e3a;<\/p>\n<p>&#8212; \u53ef\u88c5\u5165\u9a8c\u8bc1\u63d2\u4ef6;<br \/>\n1.\u6d4b\u8bd5\u9a8c\u8bc1\u63d2\u4ef6(test_plugin_server):\u4f7f\u7528\u672c\u673a\u6216\u65e7\u53e3\u4ee4\u9a8c\u8bc1\u8fdb\u884c\u8eab\u4efd\u9a8c\u8bc1,\u9002\u7528\u4e8e\u6d4b\u8bd5\u548c\u5f00\u53d1;\u6b64\u63d2\u4ef6\u4f7f\u7528auth_test_plugin.so\u6587\u4ef6;<br \/>\n2.\u5957\u63a5\u5b57\u5bf9\u7b49\u51ed\u8bc1(auth_socket):\u4ec5\u5141\u8bb8\u901a\u8fc7UNIX\u5957\u63a5\u5b57\u4ece\u5177\u6709\u76f8\u540c\u540d\u79f0\u7684UNIX\u5e10\u6237\u767b\u5f55\u7684MySQL\u7528\u6237;\u6b64\u63d2\u4ef6\u4f7f\u7528auth_socket.so\u6587\u4ef6;<br \/>\n3.PAM\u9a8c\u8bc1\u63d2\u4ef6(authentication_pam):\u662f\u4e00\u4e2a\u4f01\u4e1a\u7248\u63d2\u4ef6,\u5141\u8bb8\u4f7f\u7528\u5916\u90e8\u9a8c\u8bc1\u673a\u5236\u767b\u5f55,MySQL\u4e0d\u5b58\u50a8\u60a8\u7684\u53e3\u4ee4,\u4f46\u4f7f\u7528PAM\u673a\u5236\u4f20\u8f93\u5ba2\u6237\u673a\u63d0\u4f9b\u7684\u7528\u6237\u540d\u548c\u53e3\u4ee4\u4f9b\u64cd\u4f5c\u7cfb\u7edf\u8fdb\u884c\u9a8c\u8bc1;\u6b64\u63d2\u4ef6\u4f7f\u7528authentication_pam.so\u6587\u4ef6;<br \/>\n4.\u8981\u88c5\u5165\u5176\u4e2d\u7684\u67d0\u4e2a\u63d2\u4ef6,\u53ef\u5728\u670d\u52a1\u5668\u542f\u52a8\u65f6\u5728\u547d\u4ee4\u884c\u4e2d\u6216\u5728my.cnf\u6587\u4ef6\u4e2d\u4f7f\u7528plugin-load\u9009\u9879,\u5e76\u5c06\u8be5\u9009\u9879\u8bbe\u7f6e\u4e3a\u63d2\u4ef6\u7684\u6587\u4ef6\u540d;<br \/>\n    [mysqld]<br \/>\n    plugin-load=authentication_pam.so<br \/>\n5.\u53ef\u4ee5\u5f00\u53d1\u81ea\u5df1\u7684\u9a8c\u8bc1\u63d2\u4ef6,\u6d4b\u8bd5\u9a8c\u8bc1\u63d2\u4ef6\u9002\u7528\u4e8e\u5f00\u53d1\u8005\u521b\u5efa\u81ea\u5df1\u7684\u63d2\u4ef6;<\/p>\n<p>&#8212; PAM\u9a8c\u8bc1\u63d2\u4ef6;<br \/>\n1.PAM\u9a8c\u8bc1\u63d2\u4ef6\u662f\u4e00\u4e2a\u4f01\u4e1a\u7248\u63d2\u4ef6,\u53ef\u5411\u64cd\u4f5c\u7cfb\u7edf\u9a8c\u8bc1MySQL\u5e10\u6237;<br \/>\n2.PAM\u5b9a\u4e49\u914d\u7f6e\u9a8c\u8bc1\u7684\u670d\u52a1:\u8fd9\u4e9b\u670d\u52a1\u5b58\u50a8\u5728\/etc\/pam.d\u4e2d;<br \/>\n3.\u8be5\u63d2\u4ef6\u9488\u5bf9\u4ee5\u4e0b\u5404\u9879\u8fdb\u884c\u9a8c\u8bc1:<br \/>\n    \u2013 \u64cd\u4f5c\u7cfb\u7edf\u7528\u6237\u548c\u7ec4;<br \/>\n    \u2013 \u5916\u90e8\u9a8c\u8bc1(\u5982LDAP,Active Directory),\u56e0\u6b64\u53ef\u4ee5\u4f7f\u7528PAM\u5411\u7f51\u7edc\u4e2d\u7684\u5355\u4e2a\u5b58\u50a8\u9a8c\u8bc1\u8bb8\u591a\u670d\u52a1(\u5305\u62ecMySQL);<br \/>\n4.\u8981\u521b\u5efa\u4f7f\u7528PAM\u9a8c\u8bc1\u7684MySQL\u7528\u6237,\u8bf7\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c:CREATE USER user@host IDENTIFIED WITH authentication_pam AS &#8216;pam_service, os_group=mysql_user&#8217;;<\/p>\n<p>eg:<br \/>\n1.\u52a0\u8f7dPAM\u9a8c\u8bc1\u63d2\u4ef6,\u5728\/etc\/my.cnf\u4e2d\u6dfb\u52a0\u914d\u7f6e,\u7136\u540e\u91cd\u542fMySQL\u670d\u52a1;<br \/>\n    [mysqld]<br \/>\n    plugin-load=authentication_pam.so<br \/>\n2.\u521b\u5efaPAM\u670d\u52a1mysql-pam,\u53ef\u5728\u521b\u5efa\u6587\u4ef6\/etc\/pam.d\/mysql-pam:<br \/>\n    #%PAM-1.0<br \/>\n    auth    include  password-auth<br \/>\n    account include  password-auth<br \/>\n3.\u521b\u5efa\u64cd\u4f5c\u7cfb\u7edf\u8d26\u6237:<br \/>\n    shell> useradd bob<br \/>\n    shell> passwd bob<br \/>\n4.\u8981\u521b\u5efa\u76f4\u63a5\u6620\u5c04\u5230\u67d0\u4e2a\u64cd\u4f5c\u7cfb\u7edf\u7528\u6237\u7684MySQL\u7528\u6237,\u53ef\u4f7f\u7528\u5982\u4e0b\u8bed\u53e5:CREATE USER bob@localhost IDENTIFIED WITH authentication_pam AS &#8216;mysql-pam&#8217;;<br \/>\n5.\u5f53bob\u767b\u5f55\u65f6,MySQL\u4f1a\u5c06\u4ece\u5ba2\u6237\u673a\u63a5\u6536\u7684\u7528\u6237\u540d\u548c\u53e3\u4ee4\u4f20\u9012\u5230PAM,\u540e\u8005\u5411\u64cd\u4f5c\u7cfb\u7edf\u9a8c\u8bc1;\u5ba2\u6237\u673a\u5fc5\u987b\u4ee5\u660e\u6587\u5f62\u5f0f\u53d1\u9001\u53e3\u4ee4,\u542f\u7528\u5ba2\u6237\u7aef\u660e\u6587\u9a8c\u8bc1\u63d2\u4ef6\u4ee5\u5b9e\u73b0\u6b64\u76ee\u7684:<br \/>\n    shell> mysql &#8211;enable-cleartext-plugin -ubob -p<br \/>\n    Enter password: bob\u2019s_OS_password<\/p>\n<p>1.\u8981\u4f7f\u7528PAM\u9a8c\u8bc1\u63d2\u4ef6\u542f\u7528\u57fa\u4e8e\u7ec4\u7684\u767b\u5f55,\u53ef\u521b\u5efa\u4e00\u4e2a\u542f\u7528PAM\u7684\u533f\u540d\u4ee3\u7406\u5e10\u6237,\u8be5\u5e10\u6237\u4e0d\u4e0e\u4efb\u4f55\u7528\u6237\u5339\u914d,\u4f46\u6307\u5b9a\u4e00\u7ec4\u4ece\u64cd\u4f5c\u7cfb\u7edf\u7ec4\u5230MySQL\u7528\u6237\u7684\u6620\u5c04:CREATE USER &#8221;@&#8221; IDENTIFIED WITH authentication_pam AS &#8216;mysql-pam, sales=m_sales, finance=m_finance&#8217;;<br \/>\n2.\u4e0a\u4f8b\u5047\u5b9a\u60a8\u62e5\u6709sales\u548cfinance\u64cd\u4f5c\u7cfb\u7edf\u7ec4\u4ee5\u53cam_sales\u548cm_finance MySQL\u7528\u6237;\u7136\u540e,\u5fc5\u987b\u5411\u8be5\u533f\u540d\u4ee3\u7406\u5e10\u6237\u6388\u4e88 PROXY\u7279\u6743,\u4f7f\u5176\u80fd\u4ee5m_sales\u548cm_finance MySQL\u7528\u6237\u8eab\u4efd\u767b\u5f55:GRANT PROXY ON m_sales@localhost TO &#8221;@&#8221;; GRANT PROXY ON m_finance@localhost TO &#8221;@&#8221;;<br \/>\n3.\u73b0\u5728,\u4f5c\u4e3asales\u548cfinance\u7ec4\u6210\u5458\u7684\u7528\u6237\u53ef\u4ee5\u5728mysql\u547d\u4ee4\u884c\u63d0\u793a\u7b26\u5904\u63d0\u4f9b\u5176\u64cd\u4f5c\u7cfb\u7edf\u51ed\u8bc1,\u4ee5m_sales\u6216 m_finance MySQL\u7528\u6237\u8eab\u4efd\u767b\u5f55,\u4ece\u800c\u62e5\u6709\u6388\u4e88\u8fd9\u4e9b\u5e10\u6237\u7684\u6240\u6709\u7279\u6743;\u4f8b\u5982,\u5982\u679cpeter\u662fsales\u7ec4\u7684\u6210\u5458,\u5219\u53ef\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u767b\u5f55:<br \/>\n    shell> mysql &#8211;enable-cleartext-plugin -upeter -p<br \/>\n    Enter password: peter\u2019s_OS_password<br \/>\n    Welcome to the MySQL monitor. Commands end with ; or \\g. &#8230;<br \/>\n    mysql> SELECT CURRENT_USER();<br \/>\n    +&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br \/>\n    | CURRENT_USER() |<br \/>\n    +&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br \/>\n    | m_sales@localhost |<br \/>\n    +&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br \/>\n    1 row in set (0.01 sec)<\/p>\n<p>&#8212; \u6388\u6743;<br \/>\n1.MySQL\u6388\u6743\u7cfb\u7edf\u7684\u4e3b\u8981\u529f\u80fd\u662f\u5c06\u7ecf\u8fc7\u9a8c\u8bc1\u7684\u7528\u6237\u4e0e\u6570\u636e\u5e93\u7279\u6743(\u5982SELECT,INSERT,UPDATE\u548cDELETE)\u5173\u8054\u8d77\u6765;<br \/>\n2.\u6388\u6743\u7cfb\u7edf\u7684\u529f\u80fd\u5305\u62ec:\u53ef\u4ee5\u62e5\u6709\u533f\u540d\u7528\u6237,\u53ef\u4ee5\u542f\u7528\u7279\u5b9a\u529f\u80fd(\u5982LOAD DATA INFILE\u548c\u5404\u79cd\u7ba1\u7406\u64cd\u4f5c);<br \/>\n3.\u6388\u6743\u53ef\u786e\u4fdd\u7528\u6237\u53ea\u80fd\u6267\u884c\u5df2\u5411\u5176\u6388\u4e88\u4e86\u76f8\u5e94\u7279\u6743\u7684\u64cd\u4f5c;<br \/>\n4.\u5728\u7528\u6237\u9a8c\u8bc1\u4e4b\u540e,MySQL\u5c06\u63d0\u51fa\u4ee5\u4e0b\u95ee\u9898\u4ee5\u9a8c\u8bc1\u5e10\u6237\u7279\u6743:<br \/>\n    \u2013 \u7528\u6237\u662f\u8c01?<br \/>\n    \u2013 \u7528\u6237\u62e5\u6709\u54ea\u4e9b\u7279\u6743?<br \/>\n    \u2013 \u8fd9\u4e9b\u7279\u6743\u9002\u7528\u4e8e\u54ea\u4e9b\u65b9\u9762?<br \/>\n5.\u5fc5\u987b\u8bbe\u7f6e\u6070\u5f53\u7684\u5e10\u6237\u548c\u7279\u6743\u624d\u80fd\u8ba9\u6388\u6743\u751f\u6548;<\/p>\n<p>&#8212; \u786e\u5b9a\u76f8\u5e94\u7684\u7528\u6237\u7279\u6743;<br \/>\n1.\u53ef\u4ee5\u5728\u4e0d\u540c\u7ea7\u522b\u5411MySQL\u5e10\u6237\u6388\u4e88\u591a\u79cd\u7c7b\u578b\u7684\u7279\u6743:\u5168\u5c40\u7ea7\u522b,\u6570\u636e\u5e93\u7ea7\u522b,\u8868\u7ea7\u522b,\u5217\u7ea7\u522b,\u5b58\u50a8\u8fc7\u7a0b\u7ea7\u522b;<br \/>\n2.\u6839\u636e\u7528\u6237\u7684\u8bbf\u95ee\u8981\u6c42\u6388\u4e88\u7528\u6237\u7279\u6743:<br \/>\n    1.\u53ea\u8bfb\u7528\u6237:\u5168\u5c40,\u6570\u636e\u5e93\u6216\u8868\u7ea7\u522b\u7279\u6743,\u4f8b\u5982SELECT;<br \/>\n    2.\u4fee\u6539\u6570\u636e\u5e93\u7684\u7528\u6237:\u5168\u5c40,\u6570\u636e\u5e93\u6216\u8868\u7ea7\u522b\u7279\u6743,\u4f8b\u5982INSERT\/UPDATE\/DELETE\/CREATE\/ALTER\/DROP;<br \/>\n    3.\u7ba1\u7406\u7528\u6237:\u5168\u5c40\u7ea7\u522b\u7279\u6743,\u4f8b\u5982FILE\/PROCESS\/SHUTDOWN\/SUPER;<\/p>\n<p>&#8212; \u6388\u4e88\u7ba1\u7406\u7279\u6743;<br \/>\n1.FILE:\u5141\u8bb8\u7528\u6237\u6307\u793aMySQL\u670d\u52a1\u5668\u5728\u670d\u52a1\u5668\u4e3b\u673a\u6587\u4ef6\u7cfb\u7edf\u4e2d\u8bfb\u53d6\u548c\u5199\u5165\u6587\u4ef6;<br \/>\n2.PROCESS:\u5141\u8bb8\u7528\u6237\u4f7f\u7528SHOW PROCESSLIST\u8bed\u53e5\u67e5\u770b\u5ba2\u6237\u673a\u6b63\u5728\u6267\u884c\u7684\u6240\u6709\u8bed\u53e5;<br \/>\n3.SUPER:\u7ba1\u7406\u7279\u6743\u5141\u8bb8\u7528\u6237\u6267\u884c\u989d\u5916\u4efb\u52a1,\u5176\u4e2d\u5305\u62ec\u8bbe\u7f6e\u5168\u5c40\u53d8\u91cf\u548c\u7ec8\u6b62\u5ba2\u6237\u673a\u8fde\u63a5;<br \/>\n4.ALL\/ALL PRIVILEGES:\u6388\u4e88\u6240\u6709\u7279\u6743(\u4f46\u4e0d\u80fd\u5411\u5176\u4ed6\u7528\u6237\u6388\u4e88\u7279\u6743)\u8981\u5c3d\u53ef\u80fd\u5c11\u5730\u6388\u4e88\u7ba1\u7406\u7279\u6743,\u56e0\u4e3a\u7ba1\u7406\u7279\u6743\u53ef\u80fd\u4f1a\u88ab\u6076\u610f\u7528\u6237\u6216\u7c97\u5fc3\u7528\u6237\u6ee5\u7528;<br \/>\n5.USAGE:\u5141\u8bb8\u8fde\u63a5\u5230\u670d\u52a1\u5668,\u4f46\u6ca1\u6709\u4efb\u4f55\u7279\u6743;\u53ef\u4ee5\u4f7f\u7528\u5e10\u6237\u8bbf\u95ee\u670d\u52a1\u5668\u7528\u4e8e\u6709\u9650\u7684\u76ee\u7684,\u4f8b\u5982\u53d1\u51faSHOW VARIABLES\u6216SHOW STATUS\u8bed\u53e5;<\/p>\n<p>\u8865\u5145:MySQL\u53ef\u4ee5\u652f\u6301\u7684\u6743\u9650\u7c7b\u578b:<br \/>\n1.\u7ba1\u7406\u6743\u9650:<br \/>\n    CREATE TEMPORARY TABLES:\u521b\u5efa\u4e34\u65f6\u8868;<br \/>\n    CREATE USER:\u521b\u5efa\/\u5220\u9664\/\u91cd\u547d\u540d\u8d26\u6237;<br \/>\n    FILE:\u5728sql\u8bed\u53e5\u4e2d\u8bfb\u5199\u64cd\u4f5c\u7cfb\u7edf\u7684\u6587\u4ef6;<br \/>\n    LOCK TABLES:\u9501\u8868;<br \/>\n    PROCESS:\u67e5\u770b\u8fdb\u7a0b\u7684\u6d3b\u52a8\u72b6\u6001;<br \/>\n    RELOAD:\u91cd\u65b0\u52a0\u8f7d,FLUSH OR RESET;<br \/>\n    REPLICATION CLIENT:\u4f5c\u4e3a\u590d\u5236\u529f\u80fd\u7684\u4e3b\u673a;<br \/>\n    REPLICATION SLAVE:\u4f5c\u4e3a\u590d\u5236\u529f\u80fd\u7684\u5907\u673a;<br \/>\n    SHOW DATABASES:\u67e5\u770b\u6570\u636e\u5e93\u540d\u79f0;<br \/>\n    SHUTDOWN:\u5173\u95ed\u670d\u52a1\u5668;<br \/>\n    SUPER:\u5404\u79cd\u7ba1\u7406\u64cd\u4f5c;<br \/>\n2.\u6570\u636e\u8bbf\u95ee\u6743\u9650:<br \/>\n    ALTER:\u4fee\u6539\u8868\u7ed3\u6784,alter table;<br \/>\n    ALTER ROUTINE:\u4fee\u6539\u6216\u8005\u5220\u9664\u5b58\u50a8\u8fc7\u7a0b\u548c\u51fd\u6570;<br \/>\n    CREATE:\u521b\u5efa\u6570\u636e\u5e93\u6216\u8005\u8868;<br \/>\n    CREATE ROUTINE:\u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\u6216\u8005\u51fd\u6570;<br \/>\n    CREATE VIEW:\u521b\u5efa\u89c6\u56fe;<br \/>\n    DELETE:\u5220\u9664\u8868\u4e2d\u6570\u636e;<br \/>\n    DROP:\u5220\u9664\u6570\u636e\u5e93\u6216\u8005\u8868;<br \/>\n    EXECUTE:\u6267\u884c\u51fd\u6570\u6216\u8005\u8fc7\u7a0b;<br \/>\n    GRANT OPTION:\u6388\u6743\u7ed9\u5176\u5b83\u8d26\u6237;<br \/>\n    INDEX:\u521b\u5efa\/\u5220\u9664\u7d22\u5f15;<br \/>\n    INSERT:\u5411\u8868\u4e2d\u63d2\u5165\u8bb0\u5f55;<br \/>\n    SELECT:\u67e5\u8be2\u8868\u7684\u8bb0\u5f55;<br \/>\n    SHOW VIEW:\u67e5\u770b\u89c6\u56fe\u5b9a\u4e49,show create view;<br \/>\n    UPDATE:\u66f4\u65b0\u8868\u7684\u8bb0\u5f55:<br \/>\n3.\u7279\u6b8a\u7684\u6743\u9650:<br \/>\n    1.ALL and ALL PRIVILEGES:\u5373&#8217;all privileges except grant option&#8217;,\u6388\u4e88\u8d26\u6237\u9664\u4e86\u628a\u6743\u9650\u8d4b\u4e88\u5176\u5b83\u5e10\u53f7\u5916\u7684\u6240\u6709\u6743\u9650;<br \/>\n    2.USAGE:\u5373\u6ca1\u6709\u4efb\u4f55\u6743\u9650,\u4f46\u662f\u5b83\u53ef\u4ee5\u8fde\u63a5\u5230\u6570\u636e\u5e93\u4e0a,\u4e5f\u5728user\u8868\u4e2d\u751f\u6210\u4e00\u6761\u8bb0\u5f55.\u8fd9\u7c7b\u8d26\u6237\u7684\u5b58\u5728\u5c31\u662f\u4e3a\u4e86\u6267\u884c\u5411&#8217;show variables&#8217; or &#8216;show status&#8217;\u8fd9\u7c7b\u7684\u8bed\u53e5,\u4e5f\u4e0d\u80fd\u67e5\u770b\u8868\u7684\u5185\u5bb9;<br \/>\n4.\u6743\u9650\u7684\u7ea7\u522b<br \/>\n    1.\u6240\u6709\u7684\u6743\u9650\u90fd\u53ef\u4ee5\u88ab\u6388\u4e88\u5168\u5c40\u7684,\u4e00\u4e2a\u8d26\u6237\u62e5\u6709\u5168\u5c40\u6743\u9650,\u5b83\u53ef\u4ee5\u5728\u4efb\u4f55\u6570\u636e\u5e93\u4efb\u4f55\u65f6\u95f4\u4f7f\u7528\u6b64\u6743\u9650,\u4e00\u822c\u53ea\u6388\u4e88\u7ba1\u7406\u5458\u8fd9\u6837\u7684\u6743\u9650;<br \/>\n    2.\u4e00\u4e9b\u6743\u9650\u53ef\u4ee5\u88ab\u6388\u4e88\u7279\u5b9a\u7684\u6570\u636e\u5e93:ALTER, CREATE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, GRANT OPTION, IDEX, INSERT, LOCK TABLES, SELECT, SHOW VIEW and UPDATE.\u4e00\u4e2a\u6570\u636e\u5e93\u7ea7\u522b\u7684\u6743\u9650\u53ef\u4ee5\u5e94\u7528\u4e8e\u6240\u6709\u7684tables\u548croutines;<br \/>\n    3.\u4e00\u4e9b\u6743\u9650\u53ef\u4ee5\u88ab\u6388\u4e88\u7279\u5b9a\u7684\u8868:ALERT, CREATE, DELETE, DROP, GRANT OPTION, INDEX, INSERT, SELECT and UPDATE.\u4e00\u4e2a\u6807\u8bb0\u522b\u7684\u6743\u9650\u53ef\u4ee5\u5e94\u7528\u4e8e\u8868\u4e2d\u6240\u6709\u7684\u5217;<br \/>\n    4.\u4e00\u4e9b\u6743\u9650\u53ef\u4ee5\u88ab\u6388\u4e88\u8868\u4e2d\u7684\u5217:INSERT, SELECT and UPDATE;<br \/>\n    5.\u4e00\u4e9b\u6743\u9650\u53ef\u4ee5\u88ab\u6388\u4e88\u51fd\u6570\u548c\u5b58\u50a8\u8fc7\u7a0b:EXECUTE, ALTER ROUTINE and GRANT OPTION;<\/p>\n<p>&#8212; GRANT\u8bed\u53e5;<br \/>\n1.GRANT\u8bed\u53e5\u53ef\u521b\u5efa\u65b0\u5e10\u6237\u6216\u8005\u4fee\u6539\u73b0\u6709\u5e10\u6237;<br \/>\n2.GRANT\u8bed\u6cd5:GRANT SELECT ON world_innodb.* TO &#8216;kari&#8217;@&#8217;localhost&#8217; IDENTIFIED BY &#8216;Abc123&#8217;;<br \/>\n3.\u8be5\u8bed\u53e5\u7684\u5b50\u53e5:<br \/>\n    1.GRANT\u5173\u952e\u5b57:\u6307\u5b9a\u4e00\u4e2a\u6216\u591a\u4e2a\u6307\u793a\u8981\u6388\u4e88\u7684\u7279\u6743\u7684\u7279\u6743\u540d\u79f0;\u7279\u6743\u540d\u79f0\u4e0d\u533a\u5206\u5927\u5c0f\u5199,\u8981\u5217\u51fa\u591a\u4e2a\u7279\u6743,\u53ef\u7528\u9017\u53f7\u5206\u9694\u7279\u6743;;<br \/>\n    2.ON\u5b50\u53e5:\u6307\u5b9a\u8981\u6388\u4e88\u7684\u7279\u6743\u7684\u7ea7\u522b:<br \/>\n        1.\u5168\u5c40:*.*;<br \/>\n        2.\u6570\u636e\u5e93:<db_name>.*;<br \/>\n        3.\u8868:<\/db_name><db_name>.<table_name>;<br \/>\n        4.\u5b58\u50a8\u4f8b\u7a0b:<db_name>.<routine_name>;<br \/>\n    3.TO\u5b50\u53e5:\u6307\u5b9a\u8981\u5411\u5176\u6388\u4e88\u7279\u6743\u7684\u5e10\u6237;\u5982\u679c\u8be5\u5e10\u6237\u5c1a\u4e0d\u5b58\u5728,\u5219\u8be5\u8bed\u53e5\u5c06\u521b\u5efa\u6b64\u5e10\u6237;;<br \/>\n    4.IDENTIFIED BY\u5b50\u53e5:(\u53ef\u9009)\u5c06\u6307\u5b9a\u53e3\u4ee4\u5206\u914d\u7ed9\u5e10\u6237;\u5982\u679c\u5e10\u6237\u5df2\u5b58\u5728,\u5219\u8be5\u53e3\u4ee4\u5c06\u66ff\u6362\u65e7\u53e3\u4ee4,\u7701\u7565IDENTIFIED BY\u5b50\u53e5\u4f1a\u6709\u4ee5\u4e0b\u6548\u679c:<br \/>\n        1.\u5982\u679cTO\u5b50\u53e5\u4e2d\u7684\u5e10\u6237\u5df2\u5b58\u5728,\u5219\u5176\u53e3\u4ee4\u4fdd\u6301\u4e0d\u53d8;<br \/>\n        2.\u5982\u679cTO\u5b50\u53e5\u4e2d\u7684\u5e10\u6237\u4e0d\u5b58\u5728,\u5219\u5c06\u521b\u5efa\u8be5\u5e10\u6237,\u5e76\u4f7f\u7528\u7a7a\u767d\u53e3\u4ee4;<br \/>\n4.\u4f5c\u4e3a\u4e00\u9879\u5b89\u5168\u63aa\u65bd,\u542f\u7528NO_AUTO_CREATE_USER SQL\u6a21\u5f0f\u53ef\u9632\u6b62GRANT\u8bed\u53e5\u5728\u672a\u6307\u5b9aIDENTIFIED BY\u5b50\u53e5\u65f6\u521b\u5efa\u65b0\u5e10\u6237;<\/p>\n<p>eg:<br \/>\n1.\u6388\u6743\u8bed\u53e5:grant privileges on objects to &#8216;user&#8217;@&#8217;host&#8217; identified by &#8216;password&#8217;;<br \/>\n    1.on *.*:\u5168\u5c40\u6743\u9650,\u6240\u6709\u7684\u5bf9\u8c61,eg:grant all privileges on *.* to &#8216;u1&#8217;@&#8217;%&#8217; identified by &#8216;u1&#8217; with grant option;<br \/>\n    2.on db_name.*:\u5bf9\u6570\u636e\u5e93\u7684\u6743\u9650,eg:grant select, update on test.* to &#8216;u1&#8217;@&#8217;localhost&#8217;;<br \/>\n    3.on db_name.tbl_name:\u6570\u636e\u5e93\u4e2d\u8868\u7684\u6743\u9650,eg:grant select on mysql.user to &#8216;u1&#8217;@&#8217;localhost&#8217;;<br \/>\n    4.on db_name.tbl_name.col_name:\u6570\u636e\u5e93\u4e2d\u8868\u7684\u5217\u7684\u6743\u9650,eg:grant select(host, user) on mysql.user to &#8216;u1&#8217;@&#8217;%&#8217;;<br \/>\n    5.on db_name.routine_name:\u6570\u636e\u5e93\u4e2droutine\u7684\u6743\u9650;<br \/>\n2.\u8981\u6dfb\u52a0\u7528\u6237\u5e76\u6388\u6743\u4e00\u822c\u4f7f\u7528:grant \u6743\u96501,\u6743\u96502,&#8230; on \u6570\u636e\u5e93.\u8868 to &#8220;username&#8221;@&#8221;host&#8221; identified by &#8220;password&#8221;;(\u521b\u5efa\u7528\u6237\u7684\u540c\u65f6\u6388\u4e88\u6743\u9650)<br \/>\n    1.grant all privileges on *.* to &#8220;user1&#8243;@&#8221;%&#8221; identified by &#8220;pwd&#8221;:\u8868\u793a\u5bf9user1\u6388\u4e88\u6240\u6709\u6570\u636e\u5e93\u4e2d\u6240\u6709\u8868\u7684\u6240\u6709\u6743\u9650,\u5e76\u53ef\u4ee5\u4ece\u4efb\u610f\u5ba2\u6237\u7aef\u8fde\u63a5\u8fdb\u6765;<br \/>\n    2.grant select,insert,delete,update on mysql.user to &#8220;user1&#8243;@&#8221;192.168.0.1&#8221; identified by &#8220;pwd&#8221;:\u8868\u793a\u5bf9\u7528\u6237user1\u6388\u4e88mysql\u6570\u636e\u5e93\u7684user\u8868\u589e\u5220\u6539\u67e5\u6743\u9650,\u5e76\u4e14\u53ea\u80fd\u4ece192.168.0.1\u5ba2\u6237\u7aef\u8fde\u63a5\u8fdb\u6765;<br \/>\n    3.host\u5217\u4e3a%\u8868\u793a\u53ef\u4ee5\u4ece\u4efb\u610f\u7684\u5ba2\u6237\u7aef\u8fde\u63a5\u5230\u670d\u52a1\u5668\u7aef;<br \/>\n    5.\u4e00\u822c\u5728\u5f00\u53d1\u7684\u65f6\u5019\u4f7fhost\u4e3a%,\u5728\u751f\u4ea7\u73af\u5883\u4fee\u6539host\u7684\u5730\u5740;<\/p>\n<p>&#8212; \u663e\u793aGRANT\u7279\u6743;<br \/>\n1.\u4f7f\u7528SHOW GRANTS\u8bed\u53e5\u663e\u793a\u5e38\u89c4\u5e10\u6237\u7279\u6743:<br \/>\n    SHOW GRANTS;<br \/>\n    SHOW GRANTS FOR CURRENT_USER();<br \/>\n2.\u6307\u5b9a\u5e10\u6237\u540d\u79f0:mysql> SHOW GRANTS FOR &#8216;kari&#8217;@&#8217;myhost.example.com&#8217;;<br \/>\n3.\u53e3\u4ee4\u4ee5\u52a0\u5bc6\u5f62\u5f0f\u5b58\u50a8\u548c\u663e\u793a:\u5982\u679c\u5e10\u6237\u6709\u53e3\u4ee4,\u5219SHOW GRANTS\u5c06\u5728GRANT\u8bed\u53e5\u672b\u5c3e\u663e\u793a\u4e00\u6761IDENTIFIED BY PASSWORD\u5b50\u53e5,\u8be5\u5b50\u53e5\u53ef\u5217\u51fa\u5e10\u6237\u7684\u5168\u5c40\u7279\u6743;\u7531\u4e8e\u53e3\u4ee4\u662f \u4f7f\u7528\u5355\u5411\u52a0\u5bc6\u5b58\u50a8\u7684,\u56e0\u6b64MySQL\u65e0\u6cd5\u663e\u793a\u672a\u52a0\u5bc6\u7684\u53e3\u4ee4;<\/p>\n<p>&#8212; \u7528\u6237\u7279\u6743\u9650\u5236;<br \/>\n1.\u4e0d\u80fd\u663e\u5f0f\u62d2\u7edd\u8bbf\u95ee\u7279\u5b9a\u7528\u6237;<br \/>\n2.\u4e0d\u80fd\u5c06\u53e3\u4ee4\u4e0e\u7279\u5b9a\u5bf9\u8c61(\u5982\u6570\u636e\u5e93,\u8868\u6216\u4f8b\u7a0b)\u5173\u8054;<\/p>\n<p>&#8212; \u6388\u6743\u8868;<br \/>\n1.MySQL\u670d\u52a1\u5668\u5728\u542f\u52a8\u65f6\u5c06\u6388\u6743\u8868\u4ecemysql\u6570\u636e\u5e93\u8bfb\u53d6\u5230\u5185\u5b58\u4e2d,\u5e76\u4f7f\u6240\u6709\u8bbf\u95ee\u63a7\u5236\u51b3\u7b56\u90fd\u4ee5\u8fd9\u4e9b\u8868\u4e3a\u4f9d\u636e;\u6388\u6743\u8868\u8fd8\u6307\u793a\u6709\u5173\u5e10\u6237\u7684\u5176\u4ed6\u4fe1\u606f,\u4f8b\u5982:<br \/>\n    1.\u5e94\u9075\u5b88\u7684\u4efb\u4f55\u8d44\u6e90\u9650\u5236;<br \/>\n    2.\u4f7f\u7528\u5e10\u6237\u7684\u5ba2\u6237\u673a\u8fde\u63a5\u662f\u5426\u5fc5\u987b\u901a\u8fc7\u4f7f\u7528SSL\u7684\u5b89\u5168\u8fde\u63a5\u8fdb\u884c;<br \/>\n2.\u8868\u4e0e\u7279\u6743\u7ea7\u522b\u5bf9\u5e94:<br \/>\n    1.user:\u6bcf\u4e00\u4e2a\u8d26\u6237\u5728user\u8868\u5305\u542b\u4e00\u6761\u8bb0\u5f55,\u5b83\u8bb0\u5f55\u4e86\u7528\u6237\u62e5\u6709\u7684\u5168\u5c40\u7684\u6743\u9650,\u4e5f\u5305\u542b\u4e86\u4e00\u4e9b\u5176\u5b83\u4fe1\u606f,\u6bd4\u5982:\u4f7f\u7528\u8d44\u6e90\u7684\u9650\u5236,\u5ba2\u6237\u7aef\u8fde\u63a5\u8fdb\u6765\u662f\u5426\u9700\u8981\u4f7f\u7528SSL\u94fe\u63a5;<br \/>\n    2.db:\u5217\u51fa\u4e86\u8d26\u6237\u5bf9\u6307\u5b9a\u6570\u636e\u5e93\u7684\u6743\u9650;<br \/>\n    3.tables_priv:\u5217\u51fa\u4e86\u8d26\u6237\u5bf9\u6307\u5b9a\u8868\u7684\u6743\u9650;<br \/>\n    4.columns_priv:\u5217\u51fa\u4e86\u8d26\u6237\u5bf9\u6307\u5b9a\u5217\u7684\u6743\u9650;<br \/>\n    5.procs_priv:\u5217\u51fa\u4e86\u8d26\u6237\u5bf9\u5b58\u50a8\u8fc7\u7a0b\u548c\u51fd\u6570\u7684\u6743\u9650;<br \/>\n3.\u8fd9\u4e9b\u8868\u6307\u793a\u4e86\u6bcf\u4e2a\u5e10\u6237\u7684\u6709\u6548\u6027\u548c\u7279\u6743,\u5e76\u4e14\u6bcf\u4e2a\u7ea7\u522b\u7684\u5b89\u5168\u7a0b\u5ea6\u662f\u9012\u8fdb\u7684;<\/p>\n<p>&#8212; \u4f7f\u7528\u6388\u6743\u8868;<br \/>\n1.\u6bcf\u4e2a\u6388\u6743\u8868\u6709host\u5217\u548cuser\u5217,\u7528\u4e8e\u6807\u8bc6\u5176\u8bb0\u5f55\u9002\u7528\u7684\u5e10\u6237:<br \/>\n    1.\u5728\u8fde\u63a5\u5c1d\u8bd5\u8fc7\u7a0b\u4e2d,\u670d\u52a1\u5668\u4f1a\u786e\u5b9a\u5ba2\u6237\u673a\u662f\u5426\u80fd\u8fde\u63a5:\u5c06\u7528\u6237\u8868\u4e2d\u7684\u67d0\u4e2a\u8bb0\u5f55\u4e0e\u5ba2\u6237\u673a\u53d1\u8d77\u8fde\u63a5\u7684\u4e3b\u673a,\u5ba2\u6237\u673a\u63d0\u4f9b\u7684\u7528\u6237\u540d \u4ee5\u53ca\u5339\u914d\u8bb0\u5f55\u4e2d\u5217\u51fa\u7684\u53e3\u4ee4\u5339\u914d;<br \/>\n    2.\u5728\u8fde\u63a5\u540e,\u670d\u52a1\u5668\u4f1a\u786e\u5b9a\u6bcf\u6761\u8bed\u53e5\u7684\u8bbf\u95ee\u7279\u6743;<br \/>\n2.MySQL\u5b89\u88c5\u8fc7\u7a0b\u4f1a\u521b\u5efa\u6388\u6743\u8868:<br \/>\n    1.\u6388\u6743\u8868\u4f7f\u7528MyISAM\u5b58\u50a8\u5f15\u64ce;<br \/>\n    2.MyISAM\u4fdd\u8bc1\u53ef\u7528\u3002<\/p>\n<p>&#8212; \u5f71\u54cd\u7279\u6743\u66f4\u6539;<br \/>\n1.MySQL\u4f1a\u7ef4\u62a4\u6388\u6743\u8868\u7684\u5185\u5b58\u4e2d\u526f\u672c\u4ee5\u907f\u514d\u8bbf\u95ee\u78c1\u76d8\u4e0a\u8868\u7684\u5f00\u9500:<br \/>\n    1.\u5e94\u907f\u514d\u76f4\u63a5\u5728\u6388\u6743\u8868\u4e2d\u4fee\u6539\u7528\u6237\u5e10\u6237,\u539f\u56e0;<br \/>\n        1.\u5e10\u6237\u7ba1\u7406\u8bed\u53e5\u7684\u8bed\u6cd5\u8bbe\u8ba1\u6e05\u6670,\u7b80\u5355\u660e\u4e86;<br \/>\n        2.\u5982\u679c\u5728\u67d0\u4e2a\u5e10\u6237\u7ba1\u7406\u8bed\u53e5\u4e2d\u72af\u9519,\u8be5\u8bed\u53e5\u5c31\u4f1a\u5931\u8d25,\u4e0d\u4f1a\u66f4\u6539\u4efb\u4f55\u8bbe\u7f6e;<br \/>\n        3.\u5982\u679c\u5728\u76f4\u63a5\u66f4\u6539\u6388\u6743\u8868\u65f6\u72af\u9519,\u5219\u53ef\u80fd\u4f1a\u5c06\u6240\u6709\u7528\u6237\u9501\u5728\u7cfb\u7edf\u5916\u9762;<br \/>\n    2.\u5982\u679c\u76f4\u63a5\u4fee\u6539\u6388\u6743\u8868,\u5e94\u901a\u8fc7\u53d1\u51faFLUSH PRIVILEGES\u8bed\u53e5(\u6216\u8005\u6267\u884cmysqladmin flush-privileges\u6216mysqladmin reload\u547d\u4ee4\u663e\u5f0f\u91cd\u65b0\u88c5\u5165\u4e86\u8868)\u663e\u5f0f\u91cd\u65b0\u88c5\u5165\u6388\u6743\u8868;<br \/>\n2.\u5e10\u6237\u4fee\u6539\u8bed\u53e5(\u5982GRANT\/REVOKE\/SET PASSWORD\u548cRENAME USER)\u4f1a\u5c06\u66f4\u6539\u540c\u65f6\u5e94\u7528\u4e8e\u6388\u6743\u8868\u53ca\u5176\u5185\u5b58\u4e2d\u8868\u526f\u672c;<br \/>\n3.\u5bf9\u5168\u5c40\u7279\u6743\u548c\u53e3\u4ee4\u7684\u66f4\u6539\u4ec5\u5e94\u7528\u4e8e\u8be5\u5e10\u6237\u7684\u540e\u7eed\u8fde\u63a5;<br \/>\n4.\u5bf9\u6570\u636e\u5e93\u7ea7\u522b\u7279\u6743\u7684\u66f4\u6539\u5728\u5ba2\u6237\u673a\u7684\u4e0b\u4e00\u6761USE db_name\u8bed\u53e5\u540e\u5e94\u7528;<br \/>\n5.\u5bf9\u8868\u548c\u4f8b\u7a0b\u7279\u6743\u7684\u66f4\u6539\u4f1a\u7acb\u5373\u5e94\u7528;<\/p>\n<p>&#8212; \u64a4\u6d88\u5e10\u6237\u7279\u6743;<br \/>\n1.\u4f7f\u7528REVOKE\u8bed\u53e5\u53ef\u4ee5\u64a4\u6d88\u7279\u5b9a\u7684SQL\u8bed\u53e5\u7279\u6743:<br \/>\n    1.REVOKE\u5173\u952e\u5b57:\u6307\u5b9a\u8981\u64a4\u6d88\u7684\u7279\u6743\u5217\u8868;<br \/>\n    2.ON\u5b50\u53e5:\u6307\u793a\u8981\u64a4\u6d88\u7279\u6743\u7684\u7ea7\u522b;<br \/>\n    3.FROM\u5b50\u53e5:\u6307\u5b9a\u5e10\u6237\u540d\u79f0;<br \/>\n    eg:REVOKE DELETE, INSERT, UPDATE ON world_innodb.* FROM &#8216;Amon&#8217;@&#8217;localhost&#8217;;<br \/>\n2.\u64a4\u6d88\u7279\u6743\u4ee5\u4fbf\u5c06\u7279\u6743\u6388\u4e88\u5176\u4ed6\u7528\u6237:REVOKE GRANT OPTION ON world_innodb.* FROM &#8216;Jan&#8217;@&#8217;localhost&#8217;;<br \/>\n3.\u64a4\u6d88\u6240\u6709\u7279\u6743(\u5305\u62ec\u5411\u4ed6\u4eba\u6388\u6743):REVOKE ALL PRIVILEGES, GRANT OPTION FROM &#8216;Sasha&#8217;@&#8217;localhost&#8217;;<br \/>\n4.\u5728\u53d1\u51faREVOKE\u4e4b\u524d\u4f7f\u7528SHOW GRANTS\u8bed\u53e5\u786e\u5b9a\u8981\u64a4\u6d88\u7684\u7279\u6743,\u968f\u540e\u518d\u6b21\u786e\u8ba4\u7ed3\u679c;<\/p>\n<p>eg:\u56de\u6536\u6743\u9650:revoke prilileges on objects from &#8216;user&#8217;@&#8217;host&#8217;;<br \/>\n1.\u56de\u6536\u5168\u5c40\u6743\u9650:revoke all privileges, grant option from &#8216;u1&#8217;@&#8217;%&#8217;;<br \/>\n2.\u56de\u6536\u6570\u636e\u5e93\u7684\u6743\u9650:revoke select, grant option on mysql.* from &#8216;u1&#8217;@&#8217;%&#8217;;<br \/>\n3.\u56de\u6536\u8868\u7684\u6743\u9650:revoke select on mysql.user from &#8216;u1&#8217;@&#8217;%&#8217;;<br \/>\n4.\u56de\u6536\u5217\u7684\u6743\u9650:revoke select(host, user) on mysql.user from &#8216;u1&#8217;@&#8217;%&#8217;;<\/p>\n<p>&#8212; SHOW PROCESSLIST;<br \/>\n1.SHOW PROCESSLIST(\u67e5\u770bINFORMATION_SCHEMA.PROCESSLIST\u8868\u6216mysqladmin processlist\u547d\u4ee4\u83b7\u53d6\u7ebf\u7a0b\u4fe1\u606f)\u663e\u793a\u4e86\u6b63\u5728\u8fd0\u884c\u7684\u8fdb\u7a0b\u7ebf\u7a0b;<br \/>\n2.SHOW PROCESSLIST\u5c06\u751f\u6210\u4ee5\u4e0b\u5217:<br \/>\n    \u2013 Id:\u8fde\u63a5\u6807\u8bc6\u7b26;<br \/>\n    \u2013 User:\u53d1\u51fa\u8bed\u53e5\u7684MySQL\u7528\u6237;<br \/>\n    \u2013 Host:\u53d1\u51fa\u8bed\u53e5\u7684\u5ba2\u6237\u673a\u7684\u4e3b\u673a\u540d;<br \/>\n    \u2013 db:\u9009\u62e9\u9ed8\u8ba4\u6570\u636e\u5e93,\u5426\u5219\u4e3aNULL;<br \/>\n    \u2013 Command:\u7ebf\u7a0b\u6b63\u5728\u6267\u884c\u7684\u547d\u4ee4\u7c7b\u578b;<br \/>\n    \u2013 Time:\u7ebf\u7a0b\u5904\u4e8e\u5f53\u524d\u72b6\u6001\u7684\u65f6\u95f4(\u79d2);<br \/>\n    \u2013 State:\u6307\u793a\u7ebf\u7a0b\u6b63\u5728\u6267\u884c\u7684\u5185\u5bb9\u7684\u64cd\u4f5c,\u4e8b\u4ef6\u6216\u72b6\u6001;<br \/>\n    \u2013 Info:\u7ebf\u7a0b\u6b63\u5728\u6267\u884c\u7684\u8bed\u53e5;\u5426\u5219\u4e3aNULL;<br \/>\n3.PROCESS\u7279\u6743\u5141\u8bb8\u67e5\u770b\u6240\u6709\u7ebf\u7a0b,\u5426\u5219\u53ea\u80fd\u67e5\u770b\u81ea\u5df1\u7684\u7ebf\u7a0b;<br \/>\n4.\u5982\u679c\u51fa\u73b0\u4e86\u201c\u8fde\u63a5\u6570\u592a\u591a\u201d\u9519\u8bef,\u4f46\u5e0c\u671b\u786e\u5b9a\u6b63\u5728\u6267\u884c\u7684\u8bed\u53e5,\u5219\u4f7f\u7528SHOW FULL PROCESSLIST\u8bed\u53e5\u4f1a\u975e\u5e38\u6709\u7528;<br \/>\n5.MySQL\u989d\u5916\u4fdd\u7559\u4e86\u4e00\u4e2a\u8fde\u63a5,\u4f9b\u62e5\u6709SUPER\u7279\u6743\u7684\u5e10\u6237\u4f7f\u7528,\u8fd9\u6837\u53ef\u786e\u4fdd\u5373\u4f7f\u8fbe\u5230\u8fde\u63a5\u6570\u9650\u5236,\u7ba1\u7406\u5458\u4e5f\u59cb\u7ec8\u53ef\u4ee5\u8fde\u63a5\u5e76\u68c0\u67e5\u7cfb\u7edf(\u524d\u63d0\u662f\u5e94\u7528\u7a0b\u5e8f\u7528\u6237\u6ca1\u6709SUPER\u7279\u6743);<br \/>\n6.\u4f7f\u7528KILL\u8bed\u53e5\u53ef\u4e2d\u6b62\u8fdb\u7a0b;<\/p>\n<p>&#8212; \u7981\u7528\u5ba2\u6237\u673a\u8bbf\u95ee\u63a7\u5236;<br \/>\n\u8981\u6307\u793a\u670d\u52a1\u5668\u4e0d\u8bfb\u53d6\u6388\u6743\u8868\u5e76\u7981\u7528\u8bbf\u95ee\u63a7\u5236,\u53ef\u4f7f\u7528&#8211;skip-grant-tables\u9009\u9879:<br \/>\n1.\u6bcf\u4e2a\u8fde\u63a5\u90fd\u6210\u529f:<br \/>\n    1.\u53ef\u4ee5\u63d0\u4f9b\u4efb\u4f55\u7528\u6237\u540d\u53ca\u4efb\u4f55\u53e3\u4ee4,\u5e76\u4e14\u53ef\u4ee5\u4ece\u4efb\u4f55\u4e3b\u673a\u8fde\u63a5;<br \/>\n    2.\u8be5\u9009\u9879\u5c06\u7981\u7528\u6574\u4e2a\u7279\u6743\u7cfb\u7edf:\u4f1a\u7981\u7528\u5e10\u6237\u7ba1\u7406\u8bed\u53e5,\u5982CREATE USER,GRANT,REVOKE\u548cSET PASSWORD;<br \/>\n    3.\u8fde\u63a5\u7684\u7528\u6237\u5b9e\u9645\u4e0a\u62e5\u6709\u6240\u6709\u7279\u6743;<br \/>\n2.\u963b\u6b62\u5ba2\u6237\u673a\u8fde\u63a5:<br \/>\n    1.\u4f7f\u7528&#8211;skip-networking\u9009\u9879\u53ef\u963b\u6b62\u7f51\u7edc\u8bbf\u95ee,\u5e76\u4e14\u4ec5\u5141\u8bb8\u5728\u672c\u5730\u5957\u63a5\u5b57,\u547d\u540d\u7ba1\u9053\u6216\u5171\u4eab\u5185\u5b58\u4e0a\u8bbf\u95ee;<br \/>\n    2.\u4f7f\u7528&#8211;socket\u9009\u9879\u53ef\u5728\u975e\u6807\u51c6\u5957\u63a5\u5b57\u4e0a\u542f\u52a8\u670d\u52a1\u5668\u4ee5\u9632\u6b62\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u6216\u7528\u6237\u968f\u4fbf\u8bbf\u95ee;<\/p>\n<p>\u8865\u5145:\u5fd8\u8bb0\u7528\u6237\u5bc6\u7801:<br \/>\n1.Linux\u4e2d\u7684\u5904\u7406\u65b9\u6cd5:<br \/>\n    1.\u5173\u95ed\u670d\u52a1\u5668\u6216\u8005kill\u6389mysqld\u7684\u8fdb\u7a0b;<br \/>\n    2.\u4f7f\u7528&#8211;skip-grant-tables\u9009\u9879\u767b\u5f55,\u542f\u52a8\u670d\u52a1\u5668\u5e76\u8df3\u8fc7\u6388\u6743\u8868<br \/>\n    3.\u4f7f\u7528mysql\u767b\u5f55,\u53ef\u4ee5\u4e0d\u7528\u4f7f\u7528\u7528\u6237\u540d\u548c\u5bc6\u7801,\u5e76\u4e14\u6709\u5168\u90e8\u6743\u9650;<br \/>\n    4.\u767b\u5f55\u4e4b\u540e\u76f4\u63a5\u66f4\u65b0mysql.user\u8868\u5bc6\u7801\u5b57\u6bb5\u4e3a\u7a7a\u5373\u53ef;<br \/>\n2.Windows\u4e2d\u7684\u5904\u7406\u65b9\u6cd5:<br \/>\n    1.\u505c\u6b62mysql\u7684\u670d\u52a1:net stop mysql;<br \/>\n    2.\u5230mysql\u7684bin\u76ee\u5f55\u4e0b\u6267\u884cmysqld -nt &#8211;skip-grant-tables;<br \/>\n    3.\u5230\u65b0\u7684\u547d\u4ee4\u884c\u4e0b\u6267\u884cmysqladmin -uroot flush-privileges password &#8216;pwd&#8217;;<br \/>\n    4.\u7136\u540e\u5173\u95edmysql\u670d\u52a1:mysqladmin -uroot -p shutdown,\u6b64\u65f6\u8f93\u5165\u521a\u521a\u8bbe\u7f6e\u7684\u5bc6\u7801;<br \/>\n    5.\u542f\u52a8mysql\u670d\u52a1:net start mysql;<\/p>\n<p>&#8212; \u8bbe\u7f6e\u5e10\u6237\u8d44\u6e90\u9650\u5236;<br \/>\n1.\u901a\u8fc7\u5c06\u5168\u5c40\u53d8\u91cfMAX_USER_CONNECTIONS\u8bbe\u7f6e\u4e3a\u975e\u96f6\u503c,\u9650\u5236\u4f7f\u7528\u670d\u52a1\u5668\u8d44\u6e90:\u8fd9\u5c06\u9650\u5236\u4efb\u4f55\u4e00\u4e2a\u5e10\u6237\u7684\u540c\u65f6\u8fde\u63a5\u6570\u91cf,\u4f46\u4e0d\u4f1a\u9650\u5236\u5ba2\u6237\u673a\u5728\u8fde\u63a5\u540e\u80fd\u6267\u884c\u7684\u64cd\u4f5c;<br \/>\n2.\u9650\u5236\u5355\u4e2a\u5e10\u6237\u7684\u4ee5\u4e0b\u670d\u52a1\u5668\u8d44\u6e90:<br \/>\n    1.MAX_QUERIES_PER_HOUR(max_queries):\u4e00\u4e2a\u5e10\u6237\u6bcf\u5c0f\u65f6\u53ef\u53d1\u51fa\u7684\u67e5\u8be2\u6570\u91cf;<br \/>\n    2.MAX_UPDATES_PER_HOUR(max_updates):\u4e00\u4e2a\u5e10\u6237\u6bcf\u5c0f\u65f6\u53ef\u53d1\u51fa\u7684\u66f4\u65b0\u6570\u91cf;<br \/>\n    3.MAX_CONNECTIONS_PER_HOUR(max_connections):\u4e00\u4e2a\u5e10\u6237\u6bcf\u5c0f\u65f6\u53ef\u8fde\u63a5\u5230\u670d\u52a1\u5668\u7684\u6b21\u6570;<br \/>\n    4.MAX_USER_CONNECTIONS(max_user_connections):\u5141\u8bb8\u7684\u540c\u65f6\u8fde\u63a5\u6570\u91cf;<br \/>\n3.\u6bcf\u4e2a\u9650\u5236\u7684\u9ed8\u8ba4\u503c\u662f\u96f6,\u8868\u793a\u6ca1\u6709\u9650\u5236;<br \/>\n4.\u67e5\u770b:SELECT * FROM mysql.user\\G<br \/>\neg:<br \/>\nmysql> GRANT ALL ON *.* TO &#8216;francis&#8217;@&#8217;localhost&#8217;<br \/>\n        WITH MAX_QUERIES_PER_HOUR 20<br \/>\n             MAX_UPDATES_PER_HOUR 10<br \/>\n             MAX_CONNECTIONS_PER_HOUR 5<br \/>\n             MAX_USER_CONNECTIONS 2;<\/p>\n<p>&#8212; \u8bfe\u540e\u7ec3\u4e60;<\/p>\n<p><\/routine_name><\/db_name><\/table_name><\/db_name><\/server_host><\/password><\/username><\/password><\/username><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8212; \u7528\u6237\u7ba1\u7406\u7684\u91cd\u8981\u6027; \u5728MySQL\u4e2d\u7ba1\u7406\u7528\u6237\u65f6,\u53ef\u4ee5\u63a7\u5236\u5141\u8bb8\u6216\u4e0d\u5141\u8bb8\u7528\u6237\u6267\u884c\u7684\u64cd\u4f5c; \u2022 \u521b\u5efa\u5177 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[27,31],"class_list":["post-1309","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-mysql","tag-mysql_ocp"],"_links":{"self":[{"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/posts\/1309","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1309"}],"version-history":[{"count":1,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/posts\/1309\/revisions"}],"predecessor-version":[{"id":1310,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/posts\/1309\/revisions\/1310"}],"wp:attachment":[{"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1309"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}