简体   繁体   中英

MySQL (ClearDB) does not work on Heroku

I have multiple (FREE) apps on Heroku, all of them using PHP and MySQL. However, on one of them I constantly have issues with 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)

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. This has been going on for about 3 weeks now.

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

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.

Look like your connection string might be missing or wrong.

The ClearDB addon sets an environment variable called CLEARDB_DATABASE_URL. It contains the mysql connection string you need to use when you try to connect.

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

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