Search code examples
google-app-enginegoogle-cloud-sql

What is the username and password for Cloud SQL instance?


lets say that may app has:

GAE app id: foo123
GAE app name: foo
GAE cloud SQL instance id: foo123:myInstance

I have set the root password to "foobar" in the access control of the Cloud SQL instance.

    try{

   $pdo = new pdo("mysql:unix_socket=/cloudsql/foo:foo123:myInstance;charset=utf8", "root", "");

}catch(PDOException $ex){
    die(json_encode(
        array('outcome' => false, 'message' => 'Unable to connect')
        )
    );
}

But it can not connect. I'm testing from localhost:8080. The Cloud SQL instance location is USA and my location is Europe.

How can I see what is causing this?

Thanks. I have also tried root@"" with no success.

I'm doing exactly as the docs in here: https://developers.google.com/appengine/docs/php/cloud-sql/


Solution

  • If you are connecting from your local computer you should connect using your instance IP address. Check the Configuring Access for IP Connections section of the Cloud SQL documentation. You should also assign a password to your root user (explained also on the same page).

    I am not familiar with pdo, but a quick Google Search shows that then you could do something like this:

    new PDO('mysql:host=<cloudsql-instance-ip>', 'root', '<your root password>');