问题
Delighted to see that you have rolled out 2nd generation cloud SQL in Beta. However, I see that it is not available yet to GAE projects. Can you estimate when this link will be enabled please? We are making some big infrastructural changes in our fancy system necessitated by the slowness of Generation 1 SQL, but will stick with cloud SQL if the change is not far off.
回答1:
You can now connect to second generation Google Cloud SQL instances from App Engine apps. The connection string is slightly different from first generation instances (docs).
- Open your SQL instance in the cloud console.
- Under properties copy the "Instance connection name". Note that this is different to the 'name' of your instance and will probably follow the format
project:region:instance
. - It is normal for the UI to say "None" for authorized applications - you will still be able to connect from GAE. Note: the SQL instance and GAE app must be part of the same project.
Update: Don't have to be in the same project, you need to grant access if they are not in the same project. Ref: https://cloud.google.com/sql/docs/dev-access#gaev1-csqlv2-access
Example PHP connection code:
$con = "mysql:unix_socket=/cloudsql/CONNECTION_STRING_FROM_CONSOLE;dbname=some_db";
$this->db = new pdo($con, "root", "");
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
回答2:
As of April 27, 2016 Second Generation connectivity to App Engine is supported.
OLD content:
The Cloud SQL team is actively working on adding App Engine support for Second Generation instances. Unfortunately I can't speak about specific dates, but we hope to make it available as soon as possible.
来源:https://stackoverflow.com/questions/34413514/2nd-generation-google-cloud-sql-app-engine