Search code examples
laravelgoogle-cloud-sql

Connect local Laravel environment to Google Cloud SQL - MySQL


I try to connect my Laravel project into my local development environment to Google Cloud SQL (MySQL).

For this, I connected from my OSX Terminal with the Cloud SQL-Proxyclient to the remote database with port 3307. I can connect with my MySQL Workbench to the remote database, and I can see/change tables, ...

Into my Laravel project into .env I changed the settings:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3307
DB_DATABASE=mydatabasename
DB_USERNAME=mydatabaseusername
DB_PASSWORD=mydatabasepassword

When I open my project into the browser, into terminal I can't see, that something tries to use the connection. Into the browser I get an error message: SQLSTATE[HY000] [2002] No such file or directory (2002)

I think, the project can't connect to the remote database

How can I solve this problem?

Thanks for help!


Solution

  • Make sure you have config for right DB_HOST. Let get an IPv4 Read this for more informations: https://cloud.google.com/sql/docs/mysql/connect-external-app#appaccessIP