SQLSTATE[HY000] [2002] No such file or directory, google cloud app engine flexible

589 views
Skip to first unread message

Parth Gohel

unread,
Oct 19, 2018, 8:23:40 AM10/19/18
to Google Cloud SQL discuss

I am trying to connect cloud sql socket with google cloud app engine flexible.


My code is as bellow:


$dsn = getenv('MYSQL_DSN');
$user = getenv('MYSQL_USER');
$password = getenv('MYSQL_PASSWORD');
try {
    $db = new PDO($dsn, $user, $password);
    $statement = $db->prepare("SELECT * from user");
    $statement->execute();
    $users = $statement->fetchAll();
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}


app.yaml

runtime: php
env
: flex

runtime_config
:
    document_root
: .

env_variables
:
    MYSQL_DSN
: mysql:dbname=DATABASE;unix_socket=/cloudsql/CONNECTION_NAME
    MYSQL_USER
: username
    MYSQL_PASSWORD
: password

Getting bellow error

SQLSTATE[HY000] [2002] No such file or directory


George (Cloud Platform Support)

unread,
Oct 19, 2018, 12:41:39 PM10/19/18
to Google Cloud SQL discuss
Hello Parth, 

The recommended way to connect to Cloud SQL is detailed in the "Using Cloud SQL for MySQL" online document. The env_variables entry in your app.yaml should look analogous to: 

env_variables:
  SQL_USER: YOUR_SQL_USER
  SQL_PASSWORD: YOUR_SQL_PASSWORD
  SQL_DATABASE: YOUR_SQL_DATABASE
  # e.g. my-awesome-project:us-central1:my-cloud-sql-instance
  INSTANCE_CONNECTION_NAME: YOUR_INSTANCE_CONNECTION_NAME
Reply all
Reply to author
Forward
0 new messages