Google App Engine上的CloudSQL PDO(unix_socket)问题 [英] CloudSQL PDO(unix_socket) problems on Google App Engine

查看:316
本文介绍了Google App Engine上的CloudSQL PDO(unix_socket)问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图连接到我的CloudSQL实例FROM App Engine。我设置的方式是使用静态IP,我可以使用该IP从App Engine外部(即,在我的开发环境)连接到它。但是,当应用程序在GAE内运行时,连接到数据库的唯一方法是使用unix_socket。我在此发现的唯一文档是 Google自己的文档



根据文档,这应该足以连接:

  $ db = new PDO('mysql:unix_socket = / cloudsql / my-prj:db1; charset = utf8',
'< username>',
'< password>'
);

我可以使用我通过CloudSQL控制台创建的root密码连接到数据库,以及使用我通过本地MySQL客户端创建的其他用户。所以......如果我尝试使用IP连接GAE,它会失败(如文档所述)。但是,如果尝试使用 unix_socket = / cloudsql /...,则会出现以下错误:

  SQLSTATE [HY000] [1045]访问被用户'bookie'@'localhost'拒绝(使用密码:YES)

(当然用户名是bookie)。

as:

  $ db = new PDO('mysql:host = 123.456.789.101; unix_socket = / cloudsql / ...' ); 

我得到这个错误:

  SQLSTATE [HY000] [2002]无法找到套接字传输tcp - 您是否忘记在配置PHP时启用它? 

启发我,如果您愿意......






更新&解决方案



正如Razvan所提到的,问题在于我 以及我创建的任何其他用户都未被授予 localhost 上的任何权限。 root 在localhost上拥有特权,但它没有为其设置密码。



两种解决方案:
$ b $ 1连接时没有密码root

  $ db = new PDO('mysql:unix_socket = ...','root',''); 

2)使用google_sql.py修复其他用户的权限(或者您可以连接到某些SQL / MySQL客户端):

 让所有的`localhost`。*到bookie; 


解决方案

App Engine中的连接将显示在Cloud SQL中host ='localhost'。因此,请确保MySQL端的帐户与您尝试连接的帐户保持一致。



注意:您可以使用SHOW GRANTS FOR'bookie'@'localhost'查询特定用户的权限。


I'm trying to connect to my CloudSQL instance FROM App Engine. The way I've set it up is to use a static IP, which I can use to connect to it from outside App Engine (namely, on my development environment). However, when the app runs within GAE, the only way to connect to the database is using unix_socket. The only documentation I've found on this is Google's own docs.

According to the documentation, this should be enough to connect:

$db = new PDO('mysql:unix_socket=/cloudsql/my-prj:db1;charset=utf8',
   '<username>',
   '<password>'
);

I am able to connect to the database using the root password I've created through the CloudSQL console, as well as using the additional users I created through a local MySQL client. SO... if I try to connect on GAE using the IP, it fails (as documented). But if I try using unix_socket=/cloudsql/..., I get the following error:

SQLSTATE[HY000] [1045] Access denied for user 'bookie'@'localhost' (using password: YES)

(where the username is bookie, of course).

If I include a host setting in the PDO initialization string, such as:

$db = new PDO('mysql:host=123.456.789.101;unix_socket=/cloudsql/...');

I get this error instead:

SQLSTATE[HY000] [2002] Unable to find the socket transport "tcp" - did you forget to enable it when you configured PHP?

Enlighten me, if you will...


Update & Solution

As mentioned by Razvan, the problem was that both root as well as any other user I had created were not granted any privileges on localhost. root had privileges on localhost, but it didn't have a password set for it there.

Two solutions:

1) Connect with no password for root:

$db = new PDO('mysql:unix_socket=...', 'root', '');

2) Fix the permissions for other users using google_sql.py (or however you can connect to some SQL/MySQL client):

GRANT ALL ON `localhost`.* to bookie;

解决方案

The connections from App Engine will show in Cloud SQL with host = 'localhost'. So make sure the accounts on the mysql side are in agreement with the ones you are trying to connect with.

Note: you can the permissions for a particular user using a query like "SHOW GRANTS FOR 'bookie'@'localhost'".

这篇关于Google App Engine上的CloudSQL PDO(unix_socket)问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆