# Mysql lost connection

**URL:** <https://www.ruby-forum.com/t/mysql-lost-connection/59011>\
**Category:** Rails\
**Created:** [April 27, 2006, 9:59pm UTC](https://www.ruby-forum.com/t/mysql-lost-connection/59011 "2006-04-27T21:59:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sebastien\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba9def/32.png) [@Sebastien\_H](https://www.ruby-forum.com/u/Sebastien_H)\
**Post date:** [April 27, 2006, 9:59pm UTC](https://www.ruby-forum.com/t/mysql-lost-connection/59011/1 "2006-04-27T21:59:47Z")

</div>

Hi,

I’m lost and my mysql connection as well… I got this  
error in my production.log:

ActiveRecord::StatementInvalid (Mysql::Error: Lost connection to MySQL  
server during query: SET NAMES ‘utf8’):

Config:  
Debian Sarge (last updated), Rails 1.1.2, Webrick,  
mysqld Ver 4.1.11-Debian\_4sarge2 for pc-linux-gnu on i386  
apache2 with mod\_rewrite and webrick as proxy on 8080.

Is there a chance to get this configuration working ? I have the same  
environment on my dev machine and everything is OK on it…

When I connect on this MySQL server using mysqlclient and type the  
same command : set names ‘utf8’, everything works !

This is my database.yml:  
production:  
adapter: mysql  
database: test  
username: \*\*\*  
password: \*\*\*  
socket: /var/run/mysqld/mysqld.sock  
encoding: utf8

I have rebooted the server, MySQL, Webrick, Apache…

Really, I am lost…Any help is REALLY appreciated…

Cheers  
Seb

---

<div class="post-metadata">

**Author:** ![Sebastien\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba9def/32.png) [@Sebastien\_H](https://www.ruby-forum.com/u/Sebastien_H)\
**Post date:** [April 27, 2006, 10:07pm UTC](https://www.ruby-forum.com/t/mysql-lost-connection/59011/2 "2006-04-27T22:07:58Z")

</div>

> username: \*\*\*  
> password: \*\*\*  
> socket: /var/run/mysqld/mysqld.sock  
> encoding: utf8
> 
> I have rebooted the server, MySQL, Webrick, Apache…
> 
> Really, I am lost…Any help is REALLY appreciated…

What’s the value of wait\_timeout in mysql? Run this to see what it  
is:

```
show variables like 'wait_timeout';

```

More info here…

[http://dev.mysql.com/doc/refman/4.1/en/gone-away.html](http://dev.mysql.com/doc/refman/4.1/en/gone-away.html)

-philip

---

<div class="post-metadata">

**Author:** ![Sebastien\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba9def/32.png) [@Sebastien\_H](https://www.ruby-forum.com/u/Sebastien_H)\
**Post date:** [April 27, 2006, 11:29pm UTC](https://www.ruby-forum.com/t/mysql-lost-connection/59011/3 "2006-04-27T23:29:55Z")

</div>

On 4/27/06, Philip H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > username: \*\*\*
> 
> ```
> show variables like 'wait_timeout';
> 
> ```
> 
> More info here…
> 
> [http://dev.mysql.com/doc/refman/4.1/en/gone-away.html](http://dev.mysql.com/doc/refman/4.1/en/gone-away.html)

Hi,

Here is the value: seems correct…

mysql\> show variables like ‘wait\_timeout’;  
±--------------±------+  
| Variable\_name | Value |  
±--------------±------+  
| wait\_timeout | 28800 |  
±--------------±------+  
1 row in set (0.00 sec)

Any Ideas ?  
Seb

---

<div class="post-metadata">

**Author:** ![Sebastien\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba9def/32.png) [@Sebastien\_H](https://www.ruby-forum.com/u/Sebastien_H)\
**Post date:** [April 28, 2006, 4:57am UTC](https://www.ruby-forum.com/t/mysql-lost-connection/59011/4 "2006-04-28T04:57:30Z")

</div>

> Config:  
> Debian Sarge (last updated), Rails 1.1.2, Webrick,  
> mysqld Ver 4.1.11-Debian\_4sarge2 for pc-linux-gnu on i386  
> apache2 with mod\_rewrite and webrick as proxy on 8080.

What ruby-mysql interface do you use?  
In this case, this may be the most important.  
There are two ruby-mysql interfaces:  
(1)Ruby/MySQL  
(2)MySQL/Ruby  
and there are two Ruby/MySQL(version number is same…)

I wonder if you use different Ruby/MySQL libraries between  
production machine and dev machine.

# Ruby/MySQL library is used by rails in order to connect to MySQL.

I recommend the following basic checking and installation:

(1) check what kind of mysql library is used

Open  
“gems/activerecord-1.14.1/lib/active\_record/connection\_adapters/mysql\_adapter.rb”  
and  
insert some debug prints around (ex:puts ‘foo’)

> require\_library\_or\_gem ‘mysql’

By these debug output, you can check what kind of mysql library is used

- Ruby/MySQL on gem(if you did “gem install mysql”)
- gems/activerecord-1.14.1/lib/active\_record/vendor/mysql.rb  
(attached with Rails)

Are using libraries same for two machines?

If different and your using library on production machine is the LATTER,  
try to install by the following instruction.

(2) try to install Ruby/MySQL by yourself.

Download ruby-mysql-0.2.6.tar.gz from  
[http://www.tmtm.org/en/ruby/mysql/README\_en.html](http://www.tmtm.org/en/ruby/mysql/README_en.html)  
and install it.

By this installation, you can make mysql\_adapter.rb to use  
mysql.rb different from active\_record/vendor/mysql.rb.

active\_record/vendor/mysql.rb is patched for MySQL 4.1.11,  
but the version number is same…  
And I think this patch may not be suitable for MySQL 4.1.11 on  
Debian-Sarge.

* * *

Yasuhiro Yoshida, Software Engineer, Japan  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Sebastien\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba9def/32.png) [@Sebastien\_H](https://www.ruby-forum.com/u/Sebastien_H)\
**Post date:** [April 28, 2006, 12:06am UTC](https://www.ruby-forum.com/t/mysql-lost-connection/59011/5 "2006-04-28T00:06:38Z")

</div>

I am very lost with this problem ! Everything is chaotique !  
I need this setyp runnning ASAP … Any help is  
wanted… Please…

Cheer  
Seb

On 4/27/06, Sebastien H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > apache2 with mod\_rewrite and webrick as proxy on 8080.  
> > > database: test  
> > > is:  
> > > Here is the value: seems correct…  
> > > Seb

–  
Sebastien H.  
Open Source & Web Consultant  
EasyBox Technologies  
Rue des Terreaux 7  
CH-1003 Lausanne  
Switzerland  
Tel: + 41 21 312 58 66  
Fax: + 41 21 312 58 65

---

<div class="post-metadata">

**Author:** ![Sebastien\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba9def/32.png) [@Sebastien\_H](https://www.ruby-forum.com/u/Sebastien_H)\
**Post date:** [April 28, 2006, 10:39am UTC](https://www.ruby-forum.com/t/mysql-lost-connection/59011/6 "2006-04-28T10:39:14Z")

</div>

Thanks a lot ! That was exactly that problem !  
I’ve juste make a gem install mysql  
and everything is now OK.

Thank you.  
Cheers  
Seb

On 4/28/06, Yoshida Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> (2)MySQL/Ruby  
> (1) check what kind of mysql library is used  
> (attached with Rails)  
> and install it.  
> Yasuhiro Yoshida, Software Engineer, Japan
> 
> > > > > mysqld Ver 4.1.11-Debian\_4sarge2 for pc-linux-gnu on i386  
> > > > > adapter: mysql  
> > > > > is:
> > 
> > Fax: + 41 21 312 58 65  
> > Rails mailing list  
> > removed\_email\_address@domain.invalid  
> > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Sebastien H.  
Open Source & Web Consultant  
EasyBox Technologies  
Rue des Terreaux 7  
CH-1003 Lausanne  
Switzerland  
Tel: + 41 21 312 58 66  
Fax: + 41 21 312 58 65
