Bontina Chen
2007-Jan-16 11:18 UTC
find_by_name -> Lost connection to MYSQL server during query
* [Instant Rails Manager] 1.4 * [Ruby 1.8.5 (from the [HTTP://rubyinstaller.rubyforge.org/ One-Click Ruby Installer] 1.8.5-21) * [Ruby on Rails] 1.1.6 * [Apache] 1.3.33 * [MySQL] 4.1.9 * [MySQL/Ruby] 2.7 (native driver) * [Mongrel] 0.3.13.3 * [phpMyAdmin] 2.6.1 Above is my setting. I have no problem using rails with MYSQL until I''m using the find_by_columnname method. This is the error message when I tested in the console. ActiveRecord::StatementInvalid: Mysql::Error: Lost connection to MySQL server du ring query: SELECT * FROM lists WHERE (lists.`user_id` = 1 ) LIMIT 1 from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib /active_record/connection_adapters/abstract_adapter.rb:120:in `log'' from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib /active_record/connection_adapters/mysql_adapter.rb:184:in `execute'' from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib /active_record/connection_adapters/mysql_adapter.rb:336:in `select'' from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib /active_record/connection_adapters/mysql_adapter.rb:175:in `select_all'' from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib /active_record/base.rb:390:in `find_by_sql'' from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib /active_record/base.rb:924:in `find_every'' from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib /active_record/base.rb:918:in `find_initial'' from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib /active_record/base.rb:1103:in `send'' from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib /active_record/base.rb:1103:in `method_missing'' from (irb):26 Anyone knows how to fix it? Thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
David Harkness
2007-Jan-16 17:52 UTC
Re: find_by_name -> Lost connection to MYSQL server during q
How does "SELECT * FROM lists WHERE (lists.`user_id` = 1 ) LIMIT 1" work when you run it in a MySQL environment with the same login information that rails is using? Most of the time when I get that error, it''s a permission problem. Otherwise, I''ve had problems when I''ve used a MySQL reserved word by mistake. Just from glancing at the SQL, it looks fine. And I don''t see any reserved words from: http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html On a related note, in the newer MySQL ruby driver''s there''s a Reconnect command, that automatically reconnects to the database if you lose your connection. I don''t think it''s been intergrated with rails yet, and I''m not sure how you would turn it on though. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bontina Chen
2007-Jan-17 01:00 UTC
Re: find_by_name -> Lost connection to MYSQL server during q
David Harkness wrote:> How does "SELECT * FROM lists WHERE (lists.`user_id` = 1 ) LIMIT 1" > work when you run it in a MySQL environment with the same login > information that rails is using?SELECT * FROM lists WHERE (lists.`user_id` = 1 ) LIMIT 1 in mysql no response. But in phpmyadmin, it works. In both environment they use root without password.> > Most of the time when I get that error, it''s a permission problem. > Otherwise, I''ve had problems when I''ve used a MySQL reserved word by > mistake. > > Just from glancing at the SQL, it looks fine. > And I don''t see any reserved words from: > > http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html > > On a related note, in the newer MySQL ruby driver''s there''s a Reconnect > command, that automatically reconnects to the database if you lose your > connection. >The newer version Ruby/MySQL is 1.8? But I can still do find , just the find_by_xxx is not working. I suppose I still have connection to MySQL though.> I don''t think it''s been intergrated with rails yet, and I''m not sure how > you would turn it on though.Thanks for sharing your experience. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bontina Chen
2007-Jan-17 01:38 UTC
Re: find_by_name -> Lost connection to MYSQL server during q
David Harkness wrote:> How does "SELECT * FROM lists WHERE (lists.`user_id` = 1 ) LIMIT 1" > work when you run it in a MySQL environment with the same login > information that rails is using? > > Most of the time when I get that error, it''s a permission problem. > Otherwise, I''ve had problems when I''ve used a MySQL reserved word by > mistake. > > Just from glancing at the SQL, it looks fine. > And I don''t see any reserved words from: > > http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html > > On a related note, in the newer MySQL ruby driver''s there''s a Reconnect > command, that automatically reconnects to the database if you lose your > connection. > > I don''t think it''s been intergrated with rails yet, and I''m not sure how > you would turn it on though.I found it''s the syntax the driver generated is wrong. It should be "SELECT * FROM lists WHERE (lists.user_id = 1 ) LIMIT 1" without the single quotation. Do you know where can I modify the syntax to the right version? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
David Harkness
2007-Jan-17 16:07 UTC
Re: find_by_name -> Lost connection to MYSQL server during q
>Bontina Chen wrote: > I found it''s the syntax the driver generated is wrong. > It should be "SELECT * FROM lists WHERE (lists.user_id = 1 ) LIMIT 1" > without the single quotation. Do you know where can I modify the syntax > to the right version?Very strange, the single quotes should reduce problems, not cause them. Sounds like a naming conflict, I''d suggest changing the name of the table. Short of that try, Myobject.find_by_sql("my custom sql") or List.find_by_sql("SELECT * FROM lists WHERE (lists.user_id = 1 ) LIMIT 1") -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---