MySQL (ClearDB) not working on Heroku

I have several (FREE) Heroku applications and they all use PHP and MySQL. However, on one of them, I constantly have problems with ClearDB (MySQL). I get the following error:

SQLSTATE [HY000] [2002] Unable to 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 tried to remove the ClearDB addon and add it again several times, but this did not solve the problem. This has been going on for about 3 weeks.

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 probably can ask for support to Herku, but I would prefer to contact the community first, since now I don’t pay for Heroka.

+4
source share
1 answer

It looks like your connection string may be missing or erroneous.

The ClearDB addon is set to the CLEARDB_DATABASE_URL environment variable. It contains the mysql connection string, which you should use when trying to connect.

+2
source

Source: https://habr.com/ru/post/1498780/


All Articles