简体   繁体   English

"MySQL (ClearDB) 不适用于 Heroku"

[英]MySQL (ClearDB) does not work on Heroku

I have multiple (FREE) apps on Heroku, all of them using PHP and MySQL.我在 Heroku 上有多个(免费)应用程序,它们都使用 PHP 和 MySQL。 However, on one of them I constantly have issues with ClearDB (MySQL).但是,在其中之一上,我经常遇到 ClearDB (MySQL) 的问题。 I get the following error我收到以下错误

SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) SQLSTATE[HY000] [2002] 无法通过套接字 '/var/run/mysqld/mysqld.sock' 连接到本地 MySQL 服务器 (2)

When I try to connect to it from my local machine, it works fine.当我尝试从本地计算机连接到它时,它工作正常。 I have tried removing the ClearDB addon and adding it again multiple time, but this hasn't solved the issue.我曾尝试多次删除 ClearDB 插件并再次添加它,但这并没有解决问题。 This has been going on for about 3 weeks now.这种情况已经持续了大约 3 周。

Here is my code:这是我的代码:

    public $production = array(
    'datasource' => 'Database/Mysql',
    'persistent' => false,
    'host' => 'us-cdbr-east-04.cleardb.com',
    'login' => 'username',
    'password' => 'password',
    'database' => 'heroku_9565d18e1870f97',
    'prefix' => '',
    //'encoding' => 'utf8',
);

and here is the URL I get from Heroku/ClearDB这是我从 Heroku/ClearDB 获得的 URL

mysql://username:password@us-cdbr-east-04.cleardb.com/heroku_9565d18e1870f97?reconnect=true

Any ideas what to do now?任何想法现在该怎么做? Does my code look right?我的代码看起来正确吗? I can probably ask Heorku's support, but I would rather ask the community first, since I am not paying for Heroku at the moment.我或许可以寻求 Heorku 的支持,但我更愿意先向社区寻求帮助,因为我目前没有为 Heroku 付费。

Look like your connection string might be missing or wrong. 看起来您的连接字符串可能丢失或错误。

The ClearDB addon sets an environment variable called CLEARDB_DATABASE_URL. ClearDB附加组件设置了一个名为CLEARDB_DATABASE_URL的环境变量。 It contains the mysql connection string you need to use when you try to connect. 它包含尝试连接时需要使用的mysql连接字符串。

从 ClearDB heroku 插件切换到 JawsDB MySQL heroku 插件解决了我的问题。

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

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