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

笑着哭i 提交于 2019-12-07 06:54:45

问题


I'm having a strange problem with the latest 'mysql2' gem and Rails 3.1 I can run mysql fine from the IRB when I include the gem, but with rails whenever I attempt to save to the database in the console, or even load up the page when the server starts, i get [FATAL] Failure to Allocate Memory.

There don't seem to be any mysql logs available, and that is the only error Rails shows. Interestingly enough, when I do start a connection in the Rails console and just run a count query e.g. User.count, it works fine, but when I try to exit the console it hangs indefinitely. All the guy I'm pairing with is using the same codebase and database structure and gets no issues ...

Anyone else had this kind of issue? I tried uninstalling and reinstalling homebrew and mysql yesterday and it still happens.


回答1:


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




回答2:


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



回答3:


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



回答4:


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).




回答5:


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


来源:https://stackoverflow.com/questions/7332346/fatal-failed-to-allocate-memory-rails-3-1-and-mysql2-gem

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