{"id":2056,"date":"2011-11-05T16:55:09","date_gmt":"2011-11-05T08:55:09","guid":{"rendered":"http:\/\/www.jpuyy.com\/blog\/?p=2056"},"modified":"2017-06-27T16:58:33","modified_gmt":"2017-06-27T08:58:33","slug":"mysql-user-permissions","status":"publish","type":"post","link":"https:\/\/jpuyy.com\/?p=2056","title":{"rendered":"mysql\u521b\u5efa\u7528\u6237\u5e76\u63a7\u5236\u5176\u5bf9\u6570\u636e\u5e93\u3001\u8868\u3001\u5217\u7684\u6743\u9650"},"content":{"rendered":"<p>\u521b\u5efa\u4e00\u4e2a\u7528\u6237realabc\uff0c\u6b65\u9aa4\u4e3a\u8fdb\u5165mysql\u5e93\uff0c\u5411user\u8868\u4e2d\u63d2\u6570\u636e\uff0c\u672c\u5730\u767b\u9646\uff0c\u5bc6\u7801abc\uff1bflush privileges \u4f7f\u914d\u7f6e\u751f\u6548<\/p>\n<pre>mysql&gt; use mysql;\r\nmysql&gt; insert into user (Host,User,Password) values (\"localhost\",\"realabc\",PASSWORD(\"abc\"));\r\nmysql&gt; flush privileges;<\/pre>\n<p>\u5176\u5b9e\u76f4\u63a5\u4f7f\u7528grant\u547d\u4ee4mysql\u4e5f\u4f1a\u5e2e\u6211\u4eec\u521b\u5efa\u7528\u6237<\/p>\n<pre>grant all privileges on *.* to 'yyy'@'localhost' identified by '123';<\/pre>\n<p>\u63a5\u4e0b\u6765\u60f3\u8ba9realabc\u7528\u6237\u6765\u63d2\u5165\u3001\u66f4\u65b0discuzx\u6570\u636e\u5e93\u91cc\u7684pre_abc\u3001pre_def\u8868\uff0c\u90a3\u4e48\u80af\u5b9a\u662f\u7528insert,update,\u5f53\u7136\u8fd8\u6709select\uff0c\u8981\u4e0d\u6570\u636e\u90fd\u6ca1\u6cd5\u770b\u5230\u3002\u5148\u67e5\u770b\u5f53\u524d\u7528\u6237\u7684\u6743\u6839\uff1a<\/p>\n<pre>mysql&gt; show grants for realabc@localhost;\r\n +----------------------------------------------------------------------------------------------------------------+\r\n | Grants for realabc@localhost\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |\r\n +----------------------------------------------------------------------------------------------------------------+\r\n | GRANT USAGE ON *.* TO 'realabc'@'localhost' IDENTIFIED BY PASSWORD '*0D3CED9BEC10A777AEC23CCC353A8C08A633045E' |\r\n +----------------------------------------------------------------------------------------------------------------+\r\n 1 row in set (0.00 sec)<\/pre>\n<p>\u63a5\u4e0b\u6765\u5206\u4e24\u6b65\u8f93\u547d\u4ee4\uff0c\u63d0\u5347\u6743\u6839<\/p>\n<pre>GRANT SELECT, INSERT, UPDATE ON `discuzx`.`pre_abc` TO 'realabc'@'localhost' ;\r\nGRANT SELECT, INSERT, UPDATE ON `discuzx`.`pre_def`\u00a0TO 'realabc'@'localhost' ;<\/pre>\n<p>\u5982\u679c\u6743\u9650\u52a0\u591a\u4e86\uff0c\u53ef\u4ee5\u4f7f\u7528revoke\u6765\u56de\u6536\u6743\u9650\uff0c\u5982<\/p>\n<pre>revoke select ON database1.* from 'yyy'@'localhost' ;<\/pre>\n<pre>revoke ALL ON *.* from 'yyy'@'localhost' ;<\/pre>\n<p>\u5982\u679c\u4e3a\u67d0\u6570\u636e\u5e93\u63d0\u5347\u6240\u6709\u6743\u9650\uff0c\u4f7f\u7528<\/p>\n<pre>grant all on wordpress.* to wordpress@localhost;<\/pre>\n<p>\u8fd9\u6837\u67e5\u770b\u6743\u6839\uff0c\u5c31\u4f1a\u53d1\u73b0\u63d0\u5347\u4e86\uff0c\u8fdbphpmyadmin\u91cc\u5c31\u53ef\u4ee5\u63d2\u6570\u636e\u4e86\u3002<\/p>\n<p>\u8fdb\u4e86phpmyadmin\u53d1\u73b0\u8fd8\u6709\u4e00\u4e2ainformation_schema\uff0c\u4e0d\u60f3\u8ba9phpmyadmin\u663e\u793a<\/p>\n<p>\u627e\u5230phpmyadmin\/libraries\/config.default.php<\/p>\n<p>\u5728242\u884c\u5904\u52a0\u5165information_schema<\/p>\n<pre>$cfg['Servers'][$i]['hide_db'] = 'information_schema';<\/pre>\n<p>&nbsp;<\/p>\n<p>Update: 2017-06-27<br \/>\n\u4e0a\u8ff0\u90fd\u662f\u901a\u8fc7 grant \u521b\u5efa\u7528\u6237\uff0c\u5728 mysql 5.7 \u4f1a\u62a5 warning<\/p>\n<pre>\r\n+---------+------+------------------------------------------------------------------------------------------------------------------------------------+\r\n| Level   | Code | Message                                                                                                                            |\r\n+---------+------+------------------------------------------------------------------------------------------------------------------------------------+\r\n| Warning | 1287 | Using GRANT for creating new user is deprecated and will be removed in future release. Create new user with CREATE USER statement. |\r\n+---------+------+------------------------------------------------------------------------------------------------------------------------------------+\r\n<\/pre>\n<p>\u4f7f\u7528\u6307\u5bfc\u7684\u65b9\u5f0f\u521b\u5efa reporting \u5e93\u548c\u5bf9\u5e94\u6743\u9650<\/p>\n<pre>\r\nCREATE DATABASE `reporting` \/*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin *\/\r\ncreate reporting@'%' identified by '';                                          \r\ngrant all privileges on reporting.* to reporting@'%';\r\n<\/pre>\n<p>:)EOT<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u521b\u5efa\u4e00\u4e2a\u7528\u6237realabc\uff0c\u6b65\u9aa4\u4e3a\u8fdb\u5165mysql\u5e93\uff0c\u5411user\u8868\u4e2d\u63d2\u6570\u636e\uff0c\u672c\u5730\u767b\u9646\uff0c\u5bc6\u7801abc\uff1bflush privileges \u4f7f\u914d\u7f6e\u751f\u6548 mysql&gt; use mysql; mysql&gt; insert into user (Host,User,Password) values (&#8220;localhost&#8221;,&#8221;realabc&#8221;,PASSWORD(&#8220;abc&#8221;)); mysql&gt; flush privileges; \u5176\u5b9e\u76f4\u63a5\u4f7f\u7528grant\u547d\u4ee4mysql\u4e5f\u4f1a\u5e2e\u6211\u4eec\u521b\u5efa\u7528\u6237 grant all privileges on *.* to &#8216;yyy&#8217;@&#8217;localhost&#8217; identified by &#8216;123&#8217;; \u63a5\u4e0b\u6765\u60f3\u8ba9realabc\u7528\u6237\u6765\u63d2\u5165\u3001\u66f4\u65b0discuzx\u6570\u636e\u5e93\u91cc\u7684pre_abc\u3001pre_def\u8868\uff0c\u90a3\u4e48\u80af\u5b9a\u662f\u7528insert,update,\u5f53\u7136\u8fd8\u6709select\uff0c\u8981\u4e0d\u6570\u636e\u90fd\u6ca1\u6cd5\u770b\u5230\u3002\u5148\u67e5\u770b\u5f53\u524d\u7528\u6237\u7684\u6743\u6839\uff1a mysql&gt; show grants for realabc@localhost; +&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+ | Grants for realabc@localhost\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | +&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+ | GRANT USAGE ON *.* TO &#8216;realabc&#8217;@&#8217;localhost&#8217; IDENTIFIED BY PASSWORD &#8216;*0D3CED9BEC10A777AEC23CCC353A8C08A633045E&#8217; | +&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+ 1 row [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[65],"tags":[23],"class_list":["post-2056","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-summary"],"_links":{"self":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/2056","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2056"}],"version-history":[{"count":10,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/2056\/revisions"}],"predecessor-version":[{"id":8198,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/2056\/revisions\/8198"}],"wp:attachment":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2056"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2056"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2056"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}