# ActiveRecord::StatementInvalid Mysql::Error

**URL:** <https://www.ruby-forum.com/t/activerecord-statementinvalid-mysql-error/137368>\
**Category:** Rails\
**Created:** [May 12, 2008, 1:56pm UTC](https://www.ruby-forum.com/t/activerecord-statementinvalid-mysql-error/137368 "2008-05-12T13:56:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![suja](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba9def/32.png) [@suja](https://www.ruby-forum.com/u/suja)\
**Post date:** [May 12, 2008, 1:56pm UTC](https://www.ruby-forum.com/t/activerecord-statementinvalid-mysql-error/137368/1 "2008-05-12T13:56:07Z")

</div>

Hi,

I was deploying my application on my server, when i test my application  
i can see this error

ActiveRecord::StatementInvalid (Mysql::Error: MySQL client ran out of  
memory: SELECT \* FROM contacts ):  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active\_record/connection\_adapters/abstract\_adapter.rb:120:in  
`log' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/mysql_adapter.rb:184:in`execute’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active\_record/connection\_adapters/mysql\_adapter.rb:336:in  
`select' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/mysql_adapter.rb:175:in`select\_all’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active\_record/base.rb:390:in  
`find_by_sql' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:924:in`find\_every’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active\_record/base.rb:381:in  
`find' /app/controllers/contacts_controller.rb:38:in`list’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action\_controller/base.rb:941:in  
`send' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:941:in`perform\_action\_without\_filters’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action\_controller/filters.rb:368:in  
`perform_action_without_benchmark' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in`perform\_action\_without\_rescue’  
/usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in`perform\_action\_without\_rescue’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action\_controller/rescue.rb:82:in  
`perform_action' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:in`send’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action\_controller/base.rb:408:in  
`process_without_filters' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:377:in`process\_without\_session\_management\_support’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action\_controller/session\_management.rb:117:in  
`process' /usr/local/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/dispatcher.rb:38:in`dispatch’  
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi\_handler.rb:150:in  
`process_request' /usr/local/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:54:in`process!’  
/usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.6.1/./fcgi.rb:600:in  
`each_cgi' /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.6.1/./fcgi.rb:597:in`each’  
/usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.6.1/./fcgi.rb:597:in  
`each_cgi' /usr/local/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:53:in`process!’  
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi\_handler.rb:23:in  
`process!’  
/public/dispatch.fcgi:24

Perhaps in my development environement i don’t have this problem ☹

I don’t really understand where is the problem

Can somebody help me?

Thanks,  
Suja

---

<div class="post-metadata">

**Author:** ![suja](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba9def/32.png) [@suja](https://www.ruby-forum.com/u/suja)\
**Post date:** [May 12, 2008, 9:06pm UTC](https://www.ruby-forum.com/t/activerecord-statementinvalid-mysql-error/137368/2 "2008-05-12T21:06:09Z")

</div>

Do you have the same data in production and development? I don’t mean  
to be pedantic, but the message pretty clearly suggests you’ve run out  
of memory. If you’re dealing with a larger data set in production  
that may not be unexpected. You’ll probably need to look into  
using :limit, :offset, and paging through the data.

---

<div class="post-metadata">

**Author:** ![suja](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba9def/32.png) [@suja](https://www.ruby-forum.com/u/suja)\
**Post date:** [May 13, 2008, 9:32am UTC](https://www.ruby-forum.com/t/activerecord-statementinvalid-mysql-error/137368/3 "2008-05-13T09:32:45Z")

</div>

AndyV wrote:

> Do you have the same data in production and development? I don’t mean  
> to be pedantic, but the message pretty clearly suggests you’ve run out  
> of memory. If you’re dealing with a larger data set in production  
> that may not be unexpected. You’ll probably need to look into  
> using :limit, :offset, and paging through the data.

contact table contains only 2993 record.

---

<div class="post-metadata">

**Author:** ![suja](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba9def/32.png) [@suja](https://www.ruby-forum.com/u/suja)\
**Post date:** [May 13, 2008, 2:29pm UTC](https://www.ruby-forum.com/t/activerecord-statementinvalid-mysql-error/137368/4 "2008-05-13T14:29:45Z")

</div>

AndyV wrote:

> Do you have the same data in production and development? I don’t mean  
> to be pedantic, but the message pretty clearly suggests you’ve run out  
> of memory. If you’re dealing with a larger data set in production  
> that may not be unexpected. You’ll probably need to look into  
> using :limit, :offset, and paging through the data.

This error occurs randomly (ActiveRecord::StatementInvalid  
(Mysql::Error: MySQL client ran out of memory: SELECT \* FROM contacts  
)). ‘contact’ table contains only 2993 record. When I give limit 1000 it  
works. But when I give limit 2000 it show ‘ran out of memory’ error.

---

<div class="post-metadata">

**Author:** ![suja](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba9def/32.png) [@suja](https://www.ruby-forum.com/u/suja)\
**Post date:** [May 13, 2008, 4:20pm UTC](https://www.ruby-forum.com/t/activerecord-statementinvalid-mysql-error/137368/5 "2008-05-13T16:20:03Z")

</div>

If you get it consistenly with a limit of 2000 that does not sound  
‘random’ to me.

The important point was that the differing data (development vs  
production) is what is leading to the differing results. You have  
more data in production and the way you’ve developed this contact  
interface is causing it to run out of memory in production. You will  
need to find a way to set an appropriate ‘page’ size and page your way  
through the data.

This makes a lot of pragmatic sense – it’s unlikely that your user  
will be able to deal with 3k records. It will all be noise.

Check out the will\_paginate gem/plugin.
