{"id":200108,"date":"2025-05-06T10:27:11","date_gmt":"2025-05-06T02:27:11","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200108\/"},"modified":"2025-05-06T10:27:11","modified_gmt":"2025-05-06T02:27:11","slug":"%e5%88%9b%e5%bb%ba%e5%8f%aa%e8%83%bd%e8%ae%bf%e9%97%ae-cloudsql-%e4%b8%ad%e4%b8%80%e4%b8%aa%e6%9e%b6%e6%9e%84%e7%9a%84%e7%94%a8%e6%88%b7","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200108\/","title":{"rendered":"\u521b\u5efa\u53ea\u80fd\u8bbf\u95ee CloudSQL \u4e2d\u4e00\u4e2a\u67b6\u6784\u7684\u7528\u6237"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u521b\u5efa\u53ea\u80fd\u8bbf\u95ee CloudSQL \u4e2d\u4e00\u4e2a\u67b6\u6784\u7684\u7528\u6237<\/h1>\n<p>\u5728IT\u884c\u4e1a\u8fd9\u4e2a\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u5f88\u5feb\u7684\u884c\u4e1a\uff0c\u53ea\u6709\u4e0d\u505c\u6b62\u7684\u5b66\u4e60\uff0c\u624d\u4e0d\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u5982\u679c\u4f60\u662f\u6570\u636e\u5e93\u5b66\u4e60\u8005\uff0c\u90a3\u4e48\u672c\u6587\u300a\u521b\u5efa\u53ea\u80fd\u8bbf\u95ee CloudSQL \u4e2d\u4e00\u4e2a\u67b6\u6784\u7684\u7528\u6237\u300b\u5c31\u5f88\u9002\u5408\u4f60\uff01\u672c\u7bc7\u5185\u5bb9\u4e3b\u8981\u5305\u62ec##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240710\/1720577570668dee2278b1e.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>TL;DR:<\/strong> \u5728 Google Cloud Console \u4e2d\u521b\u5efa\u7528\u6237\u540e\uff0c\u4e0d\u8981\u5fd8\u8bb0 REVOKE &#8216;cloudsqlsuperuser&#8217;@&#8217;%&#8217; FROM &#8216;your-user&#8217;@&#8217;%&#8217;;\u5982\u679c\u60a8\u53ea\u60f3\u8ba9\u8be5\u7528\u6237\u8bbf\u95ee\u7279\u5b9a\u6a21\u5f0f\u3002<\/p>\n<hr>\n<p>\u901a\u8fc7 Google Cloud Console \u521b\u5efa MySQL \u7528\u6237\u4f1a\u81ea\u52a8\u6dfb\u52a0 cloudsqlsuperuser \u89d2\u8272\uff0c\u8be5\u89d2\u8272\u5141\u8bb8\u7528\u6237\u8bbf\u95ee\u8be5 MySQL \u5b9e\u4f8b\u4e0a\u7684\u6240\u6709\u5185\u5bb9\uff1a<\/p>\n<pre>\u663e\u793a 'user-from-gcp-console'@'%' \u7684\u8865\u52a9\u91d1\uff1b\n\n+------------------------------------------------ ------------+\n|\u6388\u4e88 user-from-gcp-console@% |\n+------------------------------------------------ ------------+\n|\u5c06 *.* \u7684\u4f7f\u7528\u6743\u6388\u4e88 `user-from-gcp-console`@`%` |\n|\u5c06 `cloudsqlsuperuser`@`%` \u6388\u4e88 `user-from-gcp-console`@`%`|\n+------------------------------------------------ ------------+\n<\/pre>\n<p>Google \u5728\u5176\u77e5\u8bc6\u5e93\u7684\u5173\u4e8e MySQL \u7528\u6237\u6587\u7ae0\u4e2d\u63d0\u5230\u4e86\u8fd9\u4e00\u70b9\u3002<\/p>\n<p>\u8981\u521b\u5efa\u53ea\u80fd\u8bbf\u95ee\u4e00\u79cd\u67b6\u6784\u7684\u7528\u6237\uff0c\u60a8\u9700\u8981\u901a\u8fc7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u521b\u5efa\u6ca1\u6709\u63a7\u5236\u53f0\u7684\u7528\u6237\uff1a<\/p>\n<pre>\u521b\u5efa\u7528\u6237\u201c\u60a8\u7684\u7528\u6237\u201d@\u201c%\u201d\u5df2\u8bc6\u522b\n    \u4f7f\u7528\u201cmysql_native_password\u201d\n    BY '';\n\n\u5c06 your-schema.* \u4e0a\u7684\u6240\u6709\u5185\u5bb9\u6388\u4e88 'your-user'@'%';\n<\/pre>\n<p>\u6216\u8005\u901a\u8fc7\u63a7\u5236\u53f0\u521b\u5efa\u7528\u6237\uff0c\u4f46\u4e0d\u8981\u5fd8\u8bb0\u5220\u9664 cloudsqlsuperuser \u89d2\u8272\uff1a<\/p>\n<pre>\/\/ \u901a\u8fc7 Google Cloud Console \u521b\u5efa\u7528\u6237\n\n\u4ece\u201c\u60a8\u7684\u7528\u6237\u201d@\u201c%\u201d\u4e2d\u64a4\u9500\u201ccloudsqlsuperuser\u201d@\u201c%\u201d\uff1b\n\u5c06 your-schema.* \u4e0a\u7684\u6240\u6709\u5185\u5bb9\u6388\u4e88 'your-user'@'%';\n<\/pre>\n<hr>\n<h3> \u7ed3\u675f\u8bed <\/h3>\n<ul>\n<li>\u7528\u6237\u7531\u7528\u6237\u540d\u548c\u4e3b\u673a\u552f\u4e00\u6807\u8bc6\u3002 % \u4ee3\u8868\u4efb\u4f55\u4e3b\u673a\uff0c\u5f53\u60a8\u5c06\u7528\u6237\u8bbf\u95ee\u9650\u5236\u4e3a\u4ec5\u67d0\u4e9b\u4e3b\u673a\u65f6\uff08\u4f8b\u5982 your-user%localhost\uff09\uff0c\u547d\u4ee4\u53ef\u80fd\u4f1a\u6709\u6240\u4e0d\u540c\u3002<\/li>\n<li>\u60a8\u53ef\u4ee5\u5c06 Cloud SQL \u4ee3\u7406\u4e0e IAM \u7ed3\u5408\u4f7f\u7528\u3002\u8bf7\u9605\u8bfb IAM \u8eab\u4efd\u9a8c\u8bc1\u6587\u7ae0\u4e86\u89e3\u66f4\u591a\u4fe1\u606f\u3002<\/li>\n<li>\u73b0\u5728\u8fd8\u6709 Cloud SQL Studio [\u9884\u89c8\u7248]\uff0c\u53ef\u80fd\u4f1a\u6d3e\u4e0a\u7528\u573a\u3002<\/li>\n<li>\u6709\u5173 MySQL \u6570\u636e\u5e93\u4e2d\u7528\u6237\u7ba1\u7406\u7684\u66f4\u591a\u4fe1\u606f\u8bf7\u70b9\u51fb\u6b64\u5904\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300a\u521b\u5efa\u53ea\u80fd\u8bbf\u95ee CloudSQL \u4e2d\u4e00\u4e2a\u67b6\u6784\u7684\u7528\u6237\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\uff01<\/p>\n<p> \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb \u5220\u9664 <\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u521b\u5efa\u53ea\u80fd\u8bbf\u95ee CloudSQL &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-200108","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=200108"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200108\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}