简体   繁体   中英

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

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

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

如果您使用安装了自制软件的mysql运行OS X Lion,可以尝试使用https://stackoverflow.com/a/9555979/1248228

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM