简体   繁体   中英

Connect Google App Engine with Google Cloud Storage in flexible environment

I want to connect from my GAE app to my Google Cloud MySQL instance. I am using the github.com/go-sql-driver/mysql driver and I followed the steps specified in the tutorial . Apparently I can connect to the database without an error but when I want to make a request I get driver: bad connection and packets.go:33: unexpected EOF . I authorised both my local IP address and the GAE app to access my database and I can connect to it from my local machine and the mysql client without a problem. I have already tried setting up my app in the standard environment and followed the advice here but it didn't work either.

That is my Go code with which I connect to the database:

host := os.Getenv("DB_HOST")
user := os.Getenv("DB_USER")
pwd := os.Getenv("DB_PWD")
connectionInfo := fmt.Sprintf("%v:%v@tcp(%v:3306)/mobile_data?parseTime=true", user, pwd, host)
db, err := sql.Open("mysql", connectionInfo)

And this is my app.yaml file:

runtime: go
vm: true
env_variables:
    "DB_HOST": "[Google Cloud MySQL Instance IPv4]"
    "DB_USER": "[User]"
    "DB_PWD": "[Password]"

Any tip or advice is greatly appreciated!

This link states that instance-level access between the app engine flexible environment and a First Generation Cloud SQL instance is not supported yet. If you want to connect to a Second Generation Cloud SQL you would have to use the Cloud SQL Proxy.
Thanks to @Tianzhou for pointing me to the link.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM