Reputation: 2274
After spending a few hours, this is the only real documentation I can find for accessing Cloud SQL from outside of GAE: https://developers.google.com/cloud-sql/docs/external
The problem is, this is for a Java application (via JDBC).
I need to access my Cloud SQL DB from within a PHP, Dart, or NodeJS application. I thought by giving my GCE instance rights to connect to Cloud SQL, this would be easy. But no arrangement of socket strings (using mysql drivers) seems to be effective.
For argument's sake, let's say I'm trying to connect with a PHP app. My mysql connection array looks like this:
(
'driver' => 'mysql',
'unix_socket' => '/cloudsql/project-id:instance-id',
'host' => 'localhost',
'database' => 'dbname',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
)
This is as close as I got, but I'll get a generic "Can't connect to local MySQL server through socket" error.
Upvotes: 0
Views: 1783
Reputation: 7029
While this is an older question, I just thought I should share what I've found in regards to this.
First off, you were attempting to connect to a MySQL Server on your GCE instance, not your remote CloudSQL instance.
To begin
Hope this helps.
Upvotes: 1
Reputation: 1263
You could connect indirectly I.E. Create a Java-based App Engine App that provides an interface to the database for you, and consume that interface from your PHP app?
For example: Java App Engine App has a 'getEmployees' method call that calls a Select query on the DB and then formats and returns the results as a JSON file. Your PHP app would then call this method and consume the JSON...
Upvotes: 0
Reputation: 618
The Cloud SQL team are working on improving the connectivity from Compute Engine. If you send this question to [email protected], they will be able to follow up.
Upvotes: 0