简体   繁体   English

无法使用谷歌应用引擎连接到MySQL数据库

[英]Unable to connect to mysql database with google app engine

I have a Google App Engine application that is running, database is set up and should be working (works with development server), but cannot connect to the database when the app is deployed. 我有一个正在运行的Google App Engine应用程序,数据库已设置且应该正常工作(与开发服务器一起使用),但在部署应用程序时无法连接到数据库。 I get the following error: 我收到以下错误:

Warning: PDO::__construct(): MySQL server has gone away in /base/data/home/apps/s~helloworldtmb/1.382580389844400668/guestbook.php on line 26 

Warning: PDO::__construct(): Error while reading greeting packet. PID=-1 in /base/data/home/apps/s~helloworldtmb/1.382580389844400668/guestbook.php on line 26 {"outcome":false,"message":"Unable to connect."}

line 26 is 第26行是

 $db = new pdo('mysql:unix_socket=/cloudsql/<helloworldtmb>:<helloworldtmb:helloo>;dbname=guestbook', 'root', 'p');

helloworldtmb is the application id and helloworldtmb:helloo is the instance name. helloworldtmb是应用程序ID和helloworldtmb:helloo是实例名称。 any ideas? 有任何想法吗?

从项目ID和Cloud SQL实例名称中删除尖括号

You didn't remove the <angle brackets> when filling in the template from the docs you followed . 您遵循文档填写模板时,您没有删除<angle brackets> Usually, when programming, when you see angle-brackets with words inside like "your app id" or "your database name", you'll want to interpret the angle-brackets as defining the start and end of where your string should be. 通常,在编程时,如果您看到里面包含单词的尖括号,如“您的应用程序ID”或“您的数据库名称”,则您需要将尖括号解释为定义字符串所在位置的起点和终点。 So, 所以,

/home/<your username>/.ssh/

Would become 会成为

/home/anon/.ssh/

And

curl -X <request method> <url>

Would become 会成为

curl -X GET http://v1-dot-api.domain.com/threads/list

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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