Unix socket in Doctrine DSN

When using the cloud sql proxy especially with cloud run for cloudsql mysql instance connections, these are available as unix sockets like this:


The gcloud documentation says with php pdo (without doctrine) the connection shall be made like this:

$dsn = sprintf(

// Connect to the database.
$conn = new PDO($dsn, $username, $password, $conn_config);

But if you set DATABASE_URL for:

        url: '%env(resolve:DATABASE_URL)%'

like this, you will receive:

An exception occurred in the driver: SQLSTATE[HY000] [2002] No such file or directory  

After some time debugging, reading multiple documentation pages and the source code of Mysql/Driver.php the native "unix_socket" seems to not be directly supported in doctrine urls.

I ended up changing it to the format of:


When beeing used with cloud run and a connected it is very important to store a DATABASE_URL in the secret manager in case it contains confidential information.

In cloudsql, doctrine, gcloud, mysql, php by
@ 11 Sep 2022, Comments at Reddit & Hackernews