Aaron Lee
2006-Feb-08 05:21 UTC
[Rails] Mysql::Error: Lost connection to MySQL server during query:
Hi, I am having Mysql connection problem for my first AddressBook application (which I took it from http://www-128.ibm.com/developerworks/linux/library/l-rubyrails/) I have gem installed the latest ruby, rails, lighttpd, fastcgi, mysql-4.1.14 on linux. Everything looks good. When I do: mysql -h localhost -u test -ptest -D AddressBook mysql> SELECT COUNT(*) FROM contacts; +----------+ | COUNT(*) | +----------+ | 1 | +----------+ 1 row in set (0.00 sec) And I have config/database.yml as development: adapter: mysql database: AddressBook username: test password: test #socket: /var/lib/mysql/mysql.sock # Connect on a TCP socket. If omitted, the adapter will connect on the # domain socket given by socket instead. host: localhost port: 3306 Here''s the stack trace: Parameters: {"action"=>"index", "controller"=>"contact"} Contact Count (0.000000) Mysql::Error: Lost connection to MySQL server during query: SELECT COUNT(*) FROM contacts ActiveRecord::StatementInvalid (Mysql::Error: Lost connection to MySQL server during query: SELECT COUNT(*) FROM contacts ): /home/aaronlee/ruby/gemrepository/gems/activerecord-1.13.2/lib/active_record/connection_adapters/abstract_adapter.rb:88:in `log'' /home/aaronlee/ruby/gemrepository/gems/activerecord-1.13.2/lib/active_record/connection_adapters/mysql_adapter.rb:180:in `execute'' /home/aaronlee/ruby/gemrepository/gems/activerecord-1.13.2/lib/active_record/connection_adapters/mysql_adapter.rb:322:in `select'' /home/aaronlee/ruby/gemrepository/gems/activerecord-1.13.2/lib/active_record/connection_adapters/mysql_adapter.rb:175:in `select_one'' /home/aaronlee/ruby/gemrepository/gems/activerecord-1.13.2/lib/active_record/connection_adapters/abstract/database_statements.rb:16:in `select_value'' /home/aaronlee/ruby/gemrepository/gems/activerecord-1.13.2/lib/active_record/base.rb:518:in `count_by_sql'' /home/aaronlee/ruby/gemrepository/gems/activerecord-1.13.2/lib/active_record/base.rb:511:in `count'' /home/aaronlee/ruby/gemrepository/gems/actionpack-1.11.2/lib/action_controller/pagination.rb:167:in `count_collection_for_pagination'' /home/aaronlee/ruby/gemrepository/gems/actionpack-1.11.2/lib/action_controller/pagination.rb:188:in `paginator_and_collection_for'' /home/aaronlee/ruby/gemrepository/gems/actionpack-1.11.2/lib/action_controller/pagination.rb:124:in `paginate'' /home/aaronlee/ruby/gemrepository/gems/actionpack-1.11.2/lib/action_controller/scaffolding.rb:101:in `list'' /home/aaronlee/ruby/gemrepository/gems/actionpack-1.11.2/lib/action_controller/scaffolding.rb:94:in `index'' /home/aaronlee/ruby/gemrepository/gems/actionpack-1.11.2/lib/action_controller/base.rb:853:in `perform_action_without_filters'' /home/aaronlee/ruby/gemrepository/gems/actionpack-1.11.2/lib/action_controller/filters.rb:332:in `perform_action_without_benchmark'' /home/aaronlee/ruby/gemrepository/gems/actionpack-1.11.2/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'' /home/aaronlee/ruby/install-1.8.4//lib/ruby/1.8/benchmark.rb:293:in `measure'' /home/aaronlee/ruby/gemrepository/gems/actionpack-1.11.2/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'' /home/aaronlee/ruby/gemrepository/gems/actionpack-1.11.2/lib/action_controller/rescue.rb:82:in `perform_action'' /home/aaronlee/ruby/gemrepository/gems/actionpack-1.11.2/lib/action_controller/base.rb:369:in `process_without_session_management_support'' /home/aaronlee/ruby/gemrepository/gems/actionpack-1.11.2/lib/action_controller/session_management.rb:116:in `process'' /home/aaronlee/ruby/gemrepository/gems/rails-1.0.0/lib/dispatcher.rb:38:in `dispatch'' /home/aaronlee/ruby/gemrepository/gems/rails-1.0.0/lib/fcgi_handler.rb:141:in `process_request'' /home/aaronlee/ruby/gemrepository/gems/rails-1.0.0/lib/fcgi_handler.rb:53:in `process!'' /home/aaronlee/ruby/install-1.8.4//lib/ruby/site_ruby/1.8/fcgi.rb:600:in `each_cgi'' /home/aaronlee/ruby/install-1.8.4//lib/ruby/site_ruby/1.8/fcgi.rb:597:in `each_cgi'' /home/aaronlee/ruby/gemrepository/gems/rails-1.0.0/lib/fcgi_handler.rb:52:in `process!'' /home/aaronlee/ruby/gemrepository/gems/rails-1.0.0/lib/fcgi_handler.rb:22:in `process!'' /home/aaronlee/ruby/AddressBook/public/dispatch.fcgi:24 Any ideas? How do I go about debugging this problem? Can I have a more verbose mode to know whether it''s talking to my localhost MySQL? -Aaron -- Posted via http://www.ruby-forum.com/.
Aaron Lee
2006-Feb-08 05:37 UTC
[Rails] Re: Mysql::Error: Lost connection to MySQL server during que
One more data point: if I start with ruby script/server webrick I actuall got /home/aaronlee/ruby/gemrepository/gems/activerecord-1.13.2/lib/active_record/connection_adapters/mysql_adapter.rb:325: [BUG] Segmentation fault ruby 1.8.4 (2005-12-24) [i686-linux] Aborted -Aaron -- Posted via http://www.ruby-forum.com/.
Craig White
2006-Feb-08 05:38 UTC
[Rails] Mysql::Error: Lost connection to MySQL server during query:
Try the socket method instead of TCP... verify that is the location of the socket... # ls -l /var/lib/mysql/mysql.sock srwxrwxrwx 1 mysql mysql 0 Jan 26 21:53 /var/lib/mysql/mysql.sock There may be a firewall interfering... or try command line connecting to TCP Port 3306... I think it''s something like... mysql -h localhost -P 3306 -u test -ptest -D AddressBook and lastly...newer versions of mysql sometimes default to older password version hash which has bit many people... # cat /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Default to using old password format for compatibility with mysql 3.x # clients (those using the mysqlclient10 compatibility package). old_passwords=0 ... As you can see...I changed it from ''1'' to ''0'' as Red Hat stuff defaults to ''old password'' and that didn''t play well with Rails. As for ''debugging'' mysql, I don''t know much besides looking at logs log/development.log - mysqld.log or ethereal trace - perhaps someone else can offer some suggestions. Craig On Wed, 2006-02-08 at 06:21 +0100, Aaron Lee wrote:> Hi, > > I am having Mysql connection problem for my first AddressBook > application (which I took it from > http://www-128.ibm.com/developerworks/linux/library/l-rubyrails/) > > I have gem installed the latest ruby, rails, lighttpd, fastcgi, > mysql-4.1.14 on linux. Everything looks good. When I do: > > mysql -h localhost -u test -ptest -D AddressBook > mysql> SELECT COUNT(*) FROM contacts; > +----------+ > | COUNT(*) | > +----------+ > | 1 | > +----------+ > 1 row in set (0.00 sec) > > And I have config/database.yml as > > development: > adapter: mysql > database: AddressBook > username: test > password: test > #socket: /var/lib/mysql/mysql.sock > > # Connect on a TCP socket. If omitted, the adapter will connect on > the > # domain socket given by socket instead. > host: localhost > port: 3306 > > > Here''s the stack trace: > Parameters: {"action"=>"index", "controller"=>"contact"} > Contact Count (0.000000) Mysql::Error: Lost connection to MySQL > server during query: SELECT COUNT(*) FROM contacts > > > ActiveRecord::StatementInvalid (Mysql::Error: Lost connection to MySQL > server during query: SELECT COUNT(*) FROM contacts ): > /home/aaronlee/ruby/gemrepository/gems/activerecord-1.13.2/lib/active_record/connection_adapters/abstract_adapter.rb:88:in > `log'' > /home/aaronlee/ruby/gemrepository/gems/activerecord-1.13.2/lib/active_record/connection_adapters/mysql_adapter.rb:180:in > `execute'' > /home/aaronlee/ruby/gemrepository/gems/activerecord-1.13.2/lib/active_record/connection_adapters/mysql_adapter.rb:322:in > `select'' > /home/aaronlee/ruby/gemrepository/gems/activerecord-1.13.2/lib/active_record/connection_adapters/mysql_adapter.rb:175:in > `select_one'' > /home/aaronlee/ruby/gemrepository/gems/activerecord-1.13.2/lib/active_record/connection_adapters/abstract/database_statements.rb:16:in > `select_value'' > /home/aaronlee/ruby/gemrepository/gems/activerecord-1.13.2/lib/active_record/base.rb:518:in > `count_by_sql'' > /home/aaronlee/ruby/gemrepository/gems/activerecord-1.13.2/lib/active_record/base.rb:511:in > `count'' > /home/aaronlee/ruby/gemrepository/gems/actionpack-1.11.2/lib/action_controller/pagination.rb:167:in > `count_collection_for_pagination'' > /home/aaronlee/ruby/gemrepository/gems/actionpack-1.11.2/lib/action_controller/pagination.rb:188:in > `paginator_and_collection_for'' > /home/aaronlee/ruby/gemrepository/gems/actionpack-1.11.2/lib/action_controller/pagination.rb:124:in > `paginate'' > /home/aaronlee/ruby/gemrepository/gems/actionpack-1.11.2/lib/action_controller/scaffolding.rb:101:in > `list'' > /home/aaronlee/ruby/gemrepository/gems/actionpack-1.11.2/lib/action_controller/scaffolding.rb:94:in > `index'' > /home/aaronlee/ruby/gemrepository/gems/actionpack-1.11.2/lib/action_controller/base.rb:853:in > `perform_action_without_filters'' > /home/aaronlee/ruby/gemrepository/gems/actionpack-1.11.2/lib/action_controller/filters.rb:332:in > `perform_action_without_benchmark'' > /home/aaronlee/ruby/gemrepository/gems/actionpack-1.11.2/lib/action_controller/benchmarking.rb:69:in > `perform_action_without_rescue'' > /home/aaronlee/ruby/install-1.8.4//lib/ruby/1.8/benchmark.rb:293:in > `measure'' > /home/aaronlee/ruby/gemrepository/gems/actionpack-1.11.2/lib/action_controller/benchmarking.rb:69:in > `perform_action_without_rescue'' > /home/aaronlee/ruby/gemrepository/gems/actionpack-1.11.2/lib/action_controller/rescue.rb:82:in > `perform_action'' > /home/aaronlee/ruby/gemrepository/gems/actionpack-1.11.2/lib/action_controller/base.rb:369:in > `process_without_session_management_support'' > /home/aaronlee/ruby/gemrepository/gems/actionpack-1.11.2/lib/action_controller/session_management.rb:116:in > `process'' > /home/aaronlee/ruby/gemrepository/gems/rails-1.0.0/lib/dispatcher.rb:38:in > `dispatch'' > /home/aaronlee/ruby/gemrepository/gems/rails-1.0.0/lib/fcgi_handler.rb:141:in > `process_request'' > /home/aaronlee/ruby/gemrepository/gems/rails-1.0.0/lib/fcgi_handler.rb:53:in > `process!'' > /home/aaronlee/ruby/install-1.8.4//lib/ruby/site_ruby/1.8/fcgi.rb:600:in > `each_cgi'' > /home/aaronlee/ruby/install-1.8.4//lib/ruby/site_ruby/1.8/fcgi.rb:597:in > `each_cgi'' > /home/aaronlee/ruby/gemrepository/gems/rails-1.0.0/lib/fcgi_handler.rb:52:in > `process!'' > /home/aaronlee/ruby/gemrepository/gems/rails-1.0.0/lib/fcgi_handler.rb:22:in > `process!'' > /home/aaronlee/ruby/AddressBook/public/dispatch.fcgi:24 > > > Any ideas? How do I go about debugging this problem? Can I have a more > verbose mode to know whether it''s talking to my localhost MySQL? > > -Aaron >
Craig White
2006-Feb-08 06:04 UTC
[Rails] Re: Mysql::Error: Lost connection to MySQL server during que
On Wed, 2006-02-08 at 06:37 +0100, Aaron Lee wrote:> One more data point: if I start with ruby script/server webrick I > actuall got > > /home/aaronlee/ruby/gemrepository/gems/activerecord-1.13.2/lib/active_record/connection_adapters/mysql_adapter.rb:325: > [BUG] Segmentation fault > ruby 1.8.4 (2005-12-24) [i686-linux] > > Aborted >---- I don''t know that this is going to help but at the top of of database.yml...it should be stating some important details... # Get the fast C bindings: # gem install mysql # (on OS X: gem install mysql -- --include=/usr/local/lib) # And be sure to use new-style password hashing: # http://dev.mysql.com/doc/refman/5.0/en/old-client.html did you do ''gem install mysql'' ? also - no tabs in database.yml (I think this has also been discussed on this message base a time or two). Seg fault though sounds like something else is the problem. Craig
Aaron Lee
2006-Feb-08 06:52 UTC
[Rails] Re: Mysql::Error: Lost connection to MySQL server during que
Craig White wrote:> Try the socket method instead of TCP... >I tried both and both failed. I also ran gem install mysql (2.7) I also tried creating a new user ruby without password and that also failed with the same Mysql::Error Lost connection ... development: adapter: mysql database: AddressBook username: test password: test socket: /var/lib/mysql/mysql.sock AND development: adapter: mysql database: AddressBook username: test password: test host: localhost port: 3306> verify that is the location of the socket... > # ls -l /var/lib/mysql/mysql.sock > srwxrwxrwx 1 mysql mysql 0 Jan 26 21:53 /var/lib/mysql/mysql.sock >It''s there> There may be a firewall interfering... > > or try command line connecting to TCP Port 3306... > > I think it''s something like... > > mysql -h localhost -P 3306 -u test -ptest -D AddressBook >This one works so I am pretty sure it''s no problem. Talking to localhost doesn''t go through firewall> and lastly...newer versions of mysql sometimes default to older password > version hash which has bit many people... > > # cat /etc/my.cnf > [mysqld] > datadir=/var/lib/mysql > socket=/var/lib/mysql/mysql.sock > # Default to using old password format for compatibility with mysql 3.x > # clients (those using the mysqlclient10 compatibility package). > old_passwords=0 > ... >I changed old_passwords from 1 to 0 and did /etc/init.d/mysqld restart but it still doesn''t help> As you can see...I changed it from ''1'' to ''0'' as Red Hat stuff defaults > to ''old password'' and that didn''t play well with Rails. > > As for ''debugging'' mysql, I don''t know much besides looking at logs > log/development.log - mysqld.log or ethereal trace - perhaps someone > else can offer some suggestions. > > Craig/var/log/mysql.log shows /usr/libexec/mysqld: ready for connections. Version: ''4.1.14'' socket: ''/var/lib/mysql/mysql.sock'' port: 3306 Source distribution Any other ideas? -Aaron -- Posted via http://www.ruby-forum.com/.
Aaron Lee
2006-Feb-08 06:56 UTC
[Rails] Re: Mysql::Error: Lost connection to MySQL server during que
The following works (I forgot to reran the new mysql password generation). mysql> grant all privileges on *.* to ''test''@''localhost'' identified by ''test'' with grant option; mysql> flush privileges; Thanks! Aaron -- Posted via http://www.ruby-forum.com/.