# Dealing with MySQL disconnects on long running scripts

**URL:** <https://www.ruby-forum.com/t/dealing-with-mysql-disconnects-on-long-running-scripts/130576>\
**Category:** Rails\
**Created:** [February 29, 2008, 3:42pm UTC](https://www.ruby-forum.com/t/dealing-with-mysql-disconnects-on-long-running-scripts/130576 "2008-02-29T15:42:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![divotdave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bbe5ce/32.png) [@divotdave](https://www.ruby-forum.com/u/divotdave)\
**Post date:** [February 29, 2008, 3:42pm UTC](https://www.ruby-forum.com/t/dealing-with-mysql-disconnects-on-long-running-scripts/130576/1 "2008-02-29T15:42:30Z")

</div>

Would anyone happen to have some advise for this?

I have a script that runs for months at a time.

On one box, I can do this without issue, on another it disconnects after  
a day.

I’ve been trying various solutions, but since it takes a day to test any  
idea, it’s been very slow going.

I’ve tried Issuing a reconnect command, after any ActiveRecord error.  
Which didn’t help.

I’m using a socket connection, not a hostname

I’m using the compiled version of the gem.

---

<div class="post-metadata">

**Author:** ![divotdave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bbe5ce/32.png) [@divotdave](https://www.ruby-forum.com/u/divotdave)\
**Post date:** [February 29, 2008, 4:26pm UTC](https://www.ruby-forum.com/t/dealing-with-mysql-disconnects-on-long-running-scripts/130576/2 "2008-02-29T16:26:33Z")

</div>

On 29 Feb 2008, at 14:42, David H. wrote:

> any  
> idea, it’s been very slow going.
> 
> I’ve tried Issuing a reconnect command, after any ActiveRecord error.  
> Which didn’t help.

Have you tried setting the active record verification\_timeout to be  
less than whatever timeout has been set on mysql ?

Fred

---

<div class="post-metadata">

**Author:** ![divotdave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bbe5ce/32.png) [@divotdave](https://www.ruby-forum.com/u/divotdave)\
**Post date:** [February 29, 2008, 5:04pm UTC](https://www.ruby-forum.com/t/dealing-with-mysql-disconnects-on-long-running-scripts/130576/3 "2008-02-29T17:04:39Z")

</div>

Been a long time since I tried that, I’ll give it another go.

I’ve seen people complain about it before, but it seems really strange  
that there isn’t an easy way to force active-record to reconnect after a  
disconnect.

From script/console, the following works.  
Mymodel.new.save #works  
Mymodel.connection.disconnect!  
Mymodel.new.save # toss an error.  
Mymodel.connection.reconnect!  
Mymodel.new.save # works

Yet the equivalent doesn’t seem to work in a long running script.

I’ll continue poking at it

Thanks for the advise

Frederick C. wrote:

> On 29 Feb 2008, at 14:42, David H. wrote:
> 
> > any  
> > idea, it’s been very slow going.
> > 
> > I’ve tried Issuing a reconnect command, after any ActiveRecord error.  
> > Which didn’t help.
> 
> Have you tried setting the active record verification\_timeout to be  
> less than whatever timeout has been set on mysql ?
> 
> Fred
