# Lost connection to Mysql

**URL:** <https://www.ruby-forum.com/t/lost-connection-to-mysql/51702>\
**Category:** Rails\
**Created:** [January 6, 2006, 12:23am UTC](https://www.ruby-forum.com/t/lost-connection-to-mysql/51702 "2006-01-06T00:23:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![robbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/2acd7d/32.png) [@robbie](https://www.ruby-forum.com/u/robbie)\
**Post date:** [January 6, 2006, 12:23am UTC](https://www.ruby-forum.com/t/lost-connection-to-mysql/51702/1 "2006-01-06T00:23:31Z")

</div>

I’m trying to set up RoR on a laptop and having all sorts of troubles.

I’m running XP SP2, I did a quick install of appache/mysql using Xampp,  
which worked fine.

I grabbed the latest windows install of ruby and rails, installed it ok  
and got it running.

The moment I try to run a rails page that queries a database, it fails  
every time, and I get the following error:

Mysql::Error: Lost connection to MySQL server during query: SHOW FIELDS  
FROM users

RAILS\_ROOT: ./script/…/config/…  
Application Trace | Framework Trace | Full Trace

c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active\_record/connection\_adapters/abstract\_adapter.rb:88:in  
`log' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/mysql_adapter.rb:180:in`execute’  
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active\_record/connection\_adapters/mysql\_adapter.rb:278:in  
`columns' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:734:in`columns’  
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active\_record/base.rb:1663:in  
`attributes_from_column_definition' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:1185:in`initialize\_without\_callbacks’  
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active\_record/callbacks.rb:236:in  
`initialize' #{RAILS_ROOT}/app/controllers/account_controller.rb:20:in`new’  
#{RAILS\_ROOT}/app/controllers/account\_controller.rb:20:in `signup’

I tried to update the mysql gem by typing gem install mysql, and when I  
do, I get the following errors as well:

C:\>gem install mysql

C:\>“c:\ruby\bin\ruby.exe” “c:\ruby\bin\gem” install mysql  
Attempting local installation of ‘mysql’  
Local gem file not found: mysql\*.gem  
Attempting remote installation of ‘mysql’  
Building native extensions. This could take a while…  
ERROR: While executing gem … (RuntimeError)  
ERROR: Failed to build gem native extension.  
Gem files will remain installed in  
c:/ruby/lib/ruby/gems/1.8/gems/mysql-2.7 for  
inspection.  
ruby extconf.rb install mysql\nchecking for mysql\_query() in  
mysqlclient.lib…  
. no  
checking for main() in m.lib… yes  
checking for mysql\_query() in mysqlclient.lib… no  
checking for main() in z.lib… no  
checking for mysql\_query() in mysqlclient.lib… no  
checking for main() in socket.lib… no  
checking for mysql\_query() in mysqlclient.lib… no  
checking for main() in nsl.lib… no  
checking for mysql\_query() in mysqlclient.lib… no  
Results logged to c:/ruby/lib/ruby/gems/1.8/gems/mysql-2.7/gem\_make.out

So what the hell am I doing wrong??? Never had the slightest problem in  
the past getting RoR working. This is my application environment:

Ruby version 1.8.2 (i386-mswin32)  
RubyGems version 0.8.10  
Rails version 1.0.0  
Active Record version 1.13.2  
Action Pack version 1.11.2  
Action Web Service version 1.0.0  
Action Mailer version 1.1.5  
Active Support version 1.2.5  
Application root C:/rails/test  
Environment development  
Database adapter mysql

thanks for any clues, sure its something simple (I hope)

---

<div class="post-metadata">

**Author:** ![robbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/2acd7d/32.png) [@robbie](https://www.ruby-forum.com/u/robbie)\
**Post date:** [January 6, 2006, 3:07am UTC](https://www.ruby-forum.com/t/lost-connection-to-mysql/51702/2 "2006-01-06T03:07:12Z")

</div>

Hi,

> The moment I try to run a rails page that queries a database, it fails  
> every time, and I get the following error:
> 
> Mysql::Error: Lost connection to MySQL server during query: SHOW  
> FIELDS FROM users

Hopefully this isn’t a misguided suggestion, but I was getting similar  
error messages when I was trying to connect to a MySQL 4.1 server that  
had old-passwords enabled.

The workaround, if you can’t disable old-passwords, is to set a blank  
password for the database user you’re working with (then the encryption  
cipher is irrelevant).

HTH,

- Andrew

---

<div class="post-metadata">

**Author:** ![robbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/2acd7d/32.png) [@robbie](https://www.ruby-forum.com/u/robbie)\
**Post date:** [January 6, 2006, 3:31am UTC](https://www.ruby-forum.com/t/lost-connection-to-mysql/51702/3 "2006-01-06T03:31:05Z")

</div>

thanks Andrew that seemed to fix it! Cheers.

---

<div class="post-metadata">

**Author:** ![robbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/2acd7d/32.png) [@robbie](https://www.ruby-forum.com/u/robbie)\
**Post date:** [January 6, 2006, 3:49am UTC](https://www.ruby-forum.com/t/lost-connection-to-mysql/51702/4 "2006-01-06T03:49:14Z")

</div>

I wrestled with this problem for a good while.

couple things I noticed:

1 - old versus new passwords might be an issue. first thing’s first,  
add a user with the old password format, and a user with the new  
password format. test with each of those users. one might work. if  
so then you’re golden. stick with that version of the password hash  
(old, new, whatever). This wasn’t what fixed my problems though

2 - connecting to a db server that was NOT localhost worked ok for me.  
Why? Hell if I know.

3 - on a lark I checked that I had mysql.so in :  
C:\ruby\lib\ruby\site\_ruby\1.8\i386-msvcrt  
and oddly enough. I didn’t. The thought occurred to me to check from  
some website I ran into … but of course I can’t find right now. If  
a google search doesn’t turn up anything that works one of us would  
have no issue sending you one.

So, yeah, that fixed it for me. Why? I have no idea but it works!

- Joel

---

<div class="post-metadata">

**Author:** ![robbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/2acd7d/32.png) [@robbie](https://www.ruby-forum.com/u/robbie)\
**Post date:** [January 6, 2006, 6:14am UTC](https://www.ruby-forum.com/t/lost-connection-to-mysql/51702/5 "2006-01-06T06:14:19Z")

</div>

Joel - I’m missing that mysql.so file you mentioned as well. If anyone  
wants to send me one to robbie dot shepherd at [gmail.com](http://gmail.com) I’d appreciate  
it!

thanks for the replies.

---

<div class="post-metadata">

**Author:** ![robbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/2acd7d/32.png) [@robbie](https://www.ruby-forum.com/u/robbie)\
**Post date:** [January 7, 2006, 1:51am UTC](https://www.ruby-forum.com/t/lost-connection-to-mysql/51702/6 "2006-01-07T01:51:10Z")

</div>

robbie shepherd wrote:

> Joel - I’m missing that mysql.so file you mentioned as well. If anyone  
> wants to send me one to robbie dot shepherd at [gmail.com](http://gmail.com) I’d appreciate  
> it!
> 
> thanks for the replies.

Go here guys  
[http://wiki.rubyonrails.org/rails/pages/HowToUseMySQLRubyBindingsOnWin32](http://wiki.rubyonrails.org/rails/pages/HowToUseMySQLRubyBindingsOnWin32).

Has the mysql.so files you’re looking for (both mysql 4 & 5). Make sure  
to put mysql.so in the C:\ruby\lib\ruby\1.8\i386-mswin32 directory. Have  
fun.
