4

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.

Benjamin Crouzier
  • 40,265
  • 44
  • 171
  • 236
Teodor Talov
  • 1,933
  • 2
  • 25
  • 39
  • Have the same issue connecting to ClearDB with MySQL workbench,. – Rails beginner Sep 05 '13 at 15:25
  • If you are sure that you are using the creds right, try removing the ClearDb addon and adding it again. That's what fixed it for me eventually. I have done it maybe 50 times and it worked at the end. – Teodor Talov Sep 05 '13 at 15:27

2 Answers2

2

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.

Chris Cherry
  • 28,118
  • 6
  • 68
  • 71
  • This is what I am using. Like I say, when I try to connect from my local env. it works fine. It just doesn't work on Heorku. – Teodor Talov Aug 25 '13 at 01:16
  • That error is indicating that mysql is attempting to connect via a unix socket instead of over TCP, maybe try to get some debugging output to make sure the value of CLEARDB_DATABASE_URL is set. – Chris Cherry Aug 25 '13 at 01:19
  • The CLEARDB_DATABASE_URL value is set. I am not sure what other debugging output I can get? – Teodor Talov Aug 25 '13 at 01:23
  • Can you post the section of code you are using to do the connection? – Chris Cherry Aug 25 '13 at 02:04
  • I see you have the params set into `$production`, is it setting/detecting the correct environment? It has to set `$default` somehow. (I'm assuming you are using CakePHP based on your code) – Chris Cherry Aug 27 '13 at 20:42
  • Yes, it's a CakePHP app, but it does detect the correct environment. When I remove the ClearDB addon and add it again it fixes it (not always) but them it breaks again on its own. – Teodor Talov Aug 27 '13 at 21:23
  • Ah I didn't realize you meant that it was working for a short time before breaking on its own, I thought you meant it didn't work at all. If it works, and then breaks without you changing any code I think the cause is likely out of your hands, at this point you have a good case to contact Heroku/ClearDB support. – Chris Cherry Aug 27 '13 at 22:49
  • Agree, since I use their free services I decided to reach out to the community first and see if anyone has encountered the same issue. I have other apps there and it has been nothing but reliable. Thanks for the help. – Teodor Talov Aug 28 '13 at 01:52
0

Switch from the ClearDB heroku add-on to JawsDB MySQL heroku add-on solve my problem.

Adriano Campos
  • 1,121
  • 7
  • 14