-Fatal- failed to allocate memory - Rails 3.1 and Mysql2 Gem

与世无争的帅哥 提交于 2019-12-05 09:36:23
nolith

If you are on OS X Lion with mysql installed with homebrew, you can try with https://stackoverflow.com/a/9555979/1248228

I also got this

[FATAL] failed to allocate memory

error and the fix was to uninstall the mysql-connector-c which I had in my brew formulas.

brew uninstall mysql-connector-c

I think this might have to do with your machine and/or MySQL configs rather than ruby. Check how much memory you are allowing MySQL to reserve. These parameters should be in the initialization or start-up files for the database. Unfortunately, I don't know exactly where to look for these files with MySQL.

I had a similar error with Postgres once because I made a typo in a config file. In Postgres the file you are looking for looks like this. It shouldn't be too different for MySQL:

#------------------------------------------------------------------------------
# RESOURCE USAGE (except WAL)
#------------------------------------------------------------------------------

# - Memory -

!!!THIS is the field you want to change!!!
shared_buffers = 28MB                   # min 128kB, default 28
                                        # (change requires restart)

#temp_buffers = 8MB                     # min 800kB
#max_prepared_transactions = 0          # zero disables the feature
                                        # (change requires restart)


# Note:  Increasing max_prepared_transactions costs ~600 bytes of shared memory
# per transaction slot, plus lock space (see max_locks_per_transaction).
# It is not advisable to set max_prepared_transactions nonzero unless you
# actively intend to use prepared transactions.
#work_mem = 1MB                         # min 64kB
#maintenance_work_mem = 16MB            # min 1MB
#max_stack_depth = 2MB                  # min 100kB
litso

I had the same issue on OS X Lion and I believe the problem was somehow related to the mysql installation on my system and the mysql2 adaptor.

I followed these instructions to install mysql - which installed mysql 5.5.15 on my machine.

Using ruby 1.9.2 and rails 3.1.3, I then got the following error:

mysql2/client.rb:44:in `connect': Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) (Mysql2::Error)

I was able to get around this issue by changing my config/database.yml to connect via the localhost (host: 127.0.0.1).

I had the same problem. Most probably, a bad practice but I had a while loop in my haml view and I had forgotten to initialize the counter and increment the counter inside loop.

- while (i < 10) do
   = i

initializing the counter and increasing it solved the problem.

- i = 0
- while (i < 10) do
  = i
  - i += 1
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!