【发布时间】:2017-01-12 17:20:40
【问题描述】:
尝试从 App Engine 连接到 Google Cloud SQL。收到错误 500 并且日志显示:“用户 'root'@'cloudsqlproxy~' 的访问被拒绝(使用密码:否)”)。 App Engine 和云 SQL 在同一个项目中。我用来连接的代码:
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
env = os.getenv('SERVER_SOFTWARE')
if (env and env.startswith('Google App Engine/')):
# Connecting from App Engine
db = MySQLdb.connect(
unix_socket='/cloudsql/<project-id>:europe-west1:<instance-name>',
user='root')
cursor = db.cursor()
cursor.execute('SELECT 1 + 1')
self.response.write('pong')
app = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)
据我了解,我所做的一切都是正确的。上面的代码我有效地复制粘贴了一个可以在 Google Dev Console 中查看的 sn-p。 StackExchange 上到处都说我不应该传递密码,所以我也不这样做。我在创建实例时更改了 root 用户密码。我不明白为什么数据库会拒绝访问 App Engine,他们在同一个项目上!有没有办法检查数据库的权限是什么?
【问题讨论】:
标签: python google-app-engine google-cloud-sql