Reputation: 7209
The following ought to work as a script, with ActiveRecord 3.1 (note that this is without Rails, not the other way around):
#!/usr/bin/env ruby
require "rubygems"
require "active_record"
dbconfig = YAML::load(File.open('database.yml'))
ActiveRecord::Base.establish_connection(dbconfig)
irb
Unfortunately, it gives the error:
... connection_specification.rb:71:in `rescue in establish_connection': ...
Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` ...
Adding the line gem 'mysql2', '<0.3'
before require "active_record"
as suggested by some previous posts (which reference 0.2.7, the 0.2 gem at the time; presently it's 0.2.18) doesn't change it.
How can I get it to work? I want ActiveRecord but not the whole of Rails.
Upvotes: 3
Views: 2366
Reputation: 7209
This has fixed my issue, at least temporarily. I haven't yet restarted, so I don't know if it'll survive that. And it seems like a dirty hack; there's got to be a better way.
I haven't yet tested Aleksei's answer above, since I'm not having the same issue after having run this command. Will update ifwhen I do.
sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib ~/.rvm/gems/`rvm current`/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
Upvotes: 0
Reputation: 5174
Run in terminal
gem install mysql2
and add row to you code require 'mysql2'
#!/usr/bin/env ruby
require "rubygems"
require 'mysql2'
require "active_record"
dbconfig = YAML::load(File.open('database.yml'))
ActiveRecord::Base.establish_connection(dbconfig)
Upvotes: 2