# MySQL lost connection errors - related to DB session store?

**URL:** <https://www.ruby-forum.com/t/mysql-lost-connection-errors-related-to-db-session-store/81648>\
**Category:** Rails\
**Created:** [January 10, 2007, 11:28pm UTC](https://www.ruby-forum.com/t/mysql-lost-connection-errors-related-to-db-session-store/81648 "2007-01-10T23:28:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [January 10, 2007, 11:28pm UTC](https://www.ruby-forum.com/t/mysql-lost-connection-errors-related-to-db-session-store/81648/1 "2007-01-10T23:28:39Z")

</div>

All,

Win XP  
MySQL 5.1.x  
Rails 1.1

I recently changed the session store in my app from file to DB (MySQL)  
and now I seem to be getting “Lost connection to MySQL server during  
query:” errors from MySQL.

I looked at several other posts about the “lost connections” issue, but  
then I looked at: [http://dev.mysql.com/doc/refman/5.0/en/gone-away.html](http://dev.mysql.com/doc/refman/5.0/en/gone-away.html)  
and found this:

"You can also get these errors if you send a query to the server that is  
incorrect or too large. If mysqld receives a packet that is too large or  
out of order, it assumes that something has gone wrong with the client  
and closes the connection. If you need big queries (for example, if you  
are working with big BLOB columns), you can increase the query limit by  
setting the server’s max\_allowed\_packet variable, which has a default  
value of 1MB. You may also need to increase the maximum packet size on  
the client end. More information on setting the packet size is given in  
Section B.2.9, â€œPacket too largeâ€. "

Has anyone seen a correlation between using the DB to store session data  
and losing connections on MySQL?

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [January 10, 2007, 11:35pm UTC](https://www.ruby-forum.com/t/mysql-lost-connection-errors-related-to-db-session-store/81648/2 "2007-01-10T23:35:11Z")

</div>

Given the above and  
[http://dev.mysql.com/doc/refman/5.0/en/packet-too-large.html](http://dev.mysql.com/doc/refman/5.0/en/packet-too-large.html), how would  
I set the “max\_allowed\_packet” on the client side of the MySQL  
connection - I assume in the MySQL connection adapter?

Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [January 11, 2007, 3:35am UTC](https://www.ruby-forum.com/t/mysql-lost-connection-errors-related-to-db-session-store/81648/3 "2007-01-11T03:35:19Z")

</div>

I agree with Benoit, you definitely need to install the native mysql  
driver. Just do:  
gem install mysql

and then pick the driver for win32, it will resolve your problems.

Joe

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [January 11, 2007, 3:13am UTC](https://www.ruby-forum.com/t/mysql-lost-connection-errors-related-to-db-session-store/81648/4 "2007-01-11T03:13:16Z")

</div>

Simply use the native win32 mySQL driver (It is available as a gem).  
The ruby one got issues with win32.  
The pb is very random. You can have everything working fine for a  
while, then suddenly got the connection lost errors.

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [January 11, 2007, 5:52am UTC](https://www.ruby-forum.com/t/mysql-lost-connection-errors-related-to-db-session-store/81648/5 "2007-01-11T05:52:04Z")

</div>

removed\_email\_address@domain.invalid wrote:

> I agree with Benoit, you definitely need to install the native mysql  
> driver. Just do:  
> gem install mysql
> 
> and then pick the driver for win32, it will resolve your problems.
> 
> Joe

I have been running this app. against MySQL on Win XP for 5 months and  
have never seen this problem before.

I’ll install the gem but I’m skeptical.

I don’t have to do anything with the AR connectors?

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [January 11, 2007, 8:16am UTC](https://www.ruby-forum.com/t/mysql-lost-connection-errors-related-to-db-session-store/81648/6 "2007-01-11T08:16:34Z")

</div>

Based slightly on [http://dev.mysql.com/doc/refman/5.0/en/gone-away.html](http://dev.mysql.com/doc/refman/5.0/en/gone-away.html),

you need to:

1. gem install mysql (I installed 2.7.3 for win32)
2. Add the directory that contains libmySQL.dll to your PATH (probably  
C:\Program Files\MySQL\MySQL Server 5.0\bin)
3. If you are running your Rails app inside of a container such as  
RadRails :), make sure you restart your app container.

NOTE: Alternatively you could move the libmySQL.dll file to a directory  
in your PATH like C:\ruby but this is unwise as you could re-break  
things when you upgrade your Ruby installation).

Things seem to be much better now.

Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [January 11, 2007, 6:00am UTC](https://www.ruby-forum.com/t/mysql-lost-connection-errors-related-to-db-session-store/81648/7 "2007-01-11T06:00:50Z")

</div>

I did gem install mysql and got version 2.7.3.

Then when I restart Mongrel, I got this error:

“The procedure entry point mysql\_stmt\_row\_tell could not be located in  
the dynamic link library LIBMYSQL.dll.”

Did I miss something?

Wes
