# Daemons causing Mysql::Error:Can't connect to local MySQL server through socket '/var/run/mysqld/my

**URL:** <https://www.ruby-forum.com/t/daemons-causing-mysql-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-my/169234>\
**Category:** Rails\
**Created:** [June 1, 2009, 8:42am UTC](https://www.ruby-forum.com/t/daemons-causing-mysql-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-my/169234 "2009-06-01T08:42:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@ram](https://www.ruby-forum.com/u/ram)\
**Post date:** [June 1, 2009, 8:42am UTC](https://www.ruby-forum.com/t/daemons-causing-mysql-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-my/169234/1 "2009-06-01T08:42:41Z")

</div>

Hi all,

Ive been having this problem for the past few days on production. I  
have a couple of daemons (using the daemons gem and daemon\_generator)  
that I run every hour on the server. One of them sends out email too  
(just in case thats relevant information). Besides this, I have 4  
Rails apps running on the server one of which contains the above  
mentioned daemons.

Now everytime I deploy, I have a couple of Capistrano tasks that stop  
the daemons before:update\_code and start them again after:update\_code.  
This I do because they stop running altogether during the deployment  
window because MySQL locks down and the daemons, when trying to  
connect to MySQL, fail.

However, once both daemons are started, everything funcitons fine for  
about 15-20 minutes after which, if I try to access any of the 4 Rails  
apps, I get “Mysql::Error:Can’t connect to local MySQL server through  
socket ‘/var/run/mysqld/mysqld.sock’”. I also sometimes get the “MySQL  
server has gone away” error. I especially get the 2nd error in the  
daemons logs when they try to run again.  
Sometimes, when I try to access one of my apps, Passenger throws an  
error saying

Passenger::Railz::ApplicationSpawner::Error  
application\_spawner.rb line 111 in `spawn\_ application’

Now all these are related only to the daemons cos if I stop them and  
reboot my server, the apps work just great.  
Googling around, I found that the “MySQL server has gone away” error  
can be fixed by adding

ActiveRecord::Base.connection.reconnect!

just before running AR queries from daemons. I tried it but it dint  
stop the apps from crashing. Is the connection apparent to anyone? Any  
ideas on how I can resolve this with least impact on my 4 apps running  
on production??

---

<div class="post-metadata">

**Author:** ![ram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@ram](https://www.ruby-forum.com/u/ram)\
**Post date:** [June 2, 2009, 7:09am UTC](https://www.ruby-forum.com/t/daemons-causing-mysql-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-my/169234/2 "2009-06-02T07:09:52Z")

</div>

Ummm. Maybe I should cut the long story short.

couple of daemons, when running on server, slow down and crash my  
Rails apps. Logs show me errors like

Mysql::Error:Can’t connect to local MySQL server through socket ‘/var/  
run/mysqld/mysqld.sock’  
&  
MySQL server has gone away

Sometimes, I also get a Passenger::Railz::ApplicationSpawner::Error.  
Any ideas on what might be going wrong? Tried  
"ActiveRecord::Base.connection.reconnect! " in the daemons but that  
dint help.
