ActiveRecord… activerecord-mysql-adapter

点点圈 提交于 2019-12-21 07:39:22

问题


This is driving me farking insane.

I'm trying to create a simple beginner app utilizing ActiveRecord to do simple database tasks. I'm NOT using rails.

I keep getting the error:

RuntimeError: Please install the mysql adapter: `gem install activerecord-mysql-adapter` (Could not find mysql (~> 2.8.1) amongst [actionmailer-3.1.3, actionpack-3.1.3, activemodel-3.1.3, activerecord-3.1.3, activerecord-sqlserver-adapter-3.1.4, activeresource-3.1.3, activesupport-3.1.3, ansi-1.4.1, arel-2.2.1, bigdecimal-1.1.0, builder-3.0.0, bundler-1.0.21, capistrano-2.9.0, coffee-rails-3.1.1, coffee-script-2.2.0, coffee-script-source-1.1.3, daemons-1.1.4, erubis-2.7.0, eventmachine-0.12.10, execjs-1.2.9, highline-1.6.8, hike-1.2.1, hpricot-0.8.5, i18n-0.6.0, io-console-0.3, jquery-rails-1.0.19, json-1.6.3, mail-2.3.0, mime-types-1.17.2, minitest-2.5.1, multi_json-1.0.4, net-scp-1.0.4, net-sftp-2.0.5, net-ssh-2.2.1, net-ssh-gateway-1.1.0, nokogiri-1.5.0, polyglot-0.3.3, rack-1.3.5, rack-cache-1.1, rack-mount-0.8.3, rack-protection-1.1.4, rack-ssl-1.3.2, rack-test-0.6.1, rails-3.1.3, railties-3.1.3, rake-0.9.2.2, rdoc-3.11, rockhands-0.0.6, sass-3.1.11, sass-rails-3.1.5, shotgun-0.9, sinatra-1.3.1, sprockets-2.0.3, sqlite3-1.3.4, thin-1.3.1, thor-0.14.6, tilt-1.3.3, treetop-1.4.10, turn-0.8.3, tzinfo-0.3.31, uglifier-1.1.0])

This gem obviously doesn't exist on rubygems, or this would be easy...

How else am I supposed to do this?

Heres the important part

ActiveRecord::Base.establish_connection(
  :adapter  => 'mysql',
  :host     => 'localhost',
  :database => 'test',
  :username => 'root',
  :password => 'password'
)

I can see whatever I change :adapter to in the hash is what it inserts into the error 'gem install activerecord-yousuck-adapter'

I've read just about every guide on google I can find...... at my wits end. I thought this would be at least a little easier.... I've spent hours and hours just fixing gem errors. Days in fact, and I have yet to write any actual ruby code. how frustrating.


回答1:


Not sure if this is your problem but try using the adapter: mysql2 driver. It's the recommended anyway since it's way faster than the standard mysql one.

Do you still get the same issue?




回答2:


After hours of fighting with this issue, Tallboy's answer worked for me on OS X:

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

Unfortunately his answer was hidden in one of the comments above; you have to click the link to expand the comment. I was getting the error message "undefined method 'init' for Mysql:Class"




回答3:


  1. I issued bundle install command, which didn't resolve the issue

  2. I found the gemfile located in c:\Sites\<>\Gemfile

  3. Added gem 'mysql' to the file by editing it in notepad++

  4. Then checked whether Mysql is avilable in the bundle using bundle show mysql

  5. After which when i issued rake db:create , I got specified file could not be found error which is was referring to libmysql.dll

  6. You can find the same in your mysql installation or you can download from the link http://www.vertstudios.com/blog/libmysqldll-32-bit-download/

  7. Copy that file to the Ruby directory bin folder. In My case I was using rubyinstaller so it was C:\RailsInstaller\Ruby1.9.3\bin

Voila. That's done.

^Note that the download link might lead to an incorrect library version. In which case, it's best to follow the link given in the message you get right after installing the mysql(2) gem to get the correct library version, otherwise it still won't work.




回答4:


We faced the same problem (because we switch from jruby to ruby)

Solved with :

  • adapter: mysql2 (in database.yml)
  • gem 'mysql2' (in the gemfile)


来源:https://stackoverflow.com/questions/8374505/activerecord-activerecord-mysql-adapter

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