Connect local Laravel environment to Google Cloud SQL - MySQL

僤鯓⒐⒋嵵緔 提交于 2020-03-25 19:04:48

问题


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!


回答1:


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




回答2:


I added now the public IP address of the server, and I added my local IP address to allowed IP adresses for the MySQL server. Now it works.




回答3:


While the Cloud SQL Proxy connects to your database on port 3307, you want to connect to the Cloud SQL proxy on port 3306 (this is the default mysql port). You can also specify a custom port by updating the instances argument:

./cloud_sql_proxy -instances=my-project:us-central1:sql-inst=tcp:3306 &


来源:https://stackoverflow.com/questions/58216696/connect-local-laravel-environment-to-google-cloud-sql-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!