Hey, folks -
I’ve got a newbie question that I couldn’t find anywhere in the forum
archives. Just installed RoR on Mac OSX (Leopard), and wanted to connect
it to MySQL instead of SQLite. I downloaded the gem:
sudo gem install mysql – --with-mysql-dir=/usr/local/mysql
I create my databases in MySQL (rubytryout_development, rubytryout_test,
and rubytryout_production), but when I load up Ruby and try to create a
class, here’s what happens:
class Book < ActiveRecord::Base; end
=> nilbook = Book.new
Mysql::Error: #42000Incorrect database name ‘db/rubytryout_development’
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/vendor/mysql.rb:523:in
read' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/vendor/mysql.rb:153:in
real_connect’
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/connection_adapters/mysql_adapter.rb:389:in
connect' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/connection_adapters/mysql_adapter.rb:152:in
initialize’
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/connection_adapters/mysql_adapter.rb:82:in
new' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/connection_adapters/mysql_adapter.rb:82:in
mysql_connection’
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/connection_adapters/abstract/connection_specification.rb:262:in
send' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/connection_adapters/abstract/connection_specification.rb:262:in
connection_without_query_cache=’
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/query_cache.rb:54:in
connection=' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/connection_adapters/abstract/connection_specification.rb:230:in
retrieve_connection’
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/connection_adapters/abstract/connection_specification.rb:78:in
connection' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/base.rb:763:in
columns’
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/base.rb:2063:in
attributes_from_column_definition_without_lock' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/locking/optimistic.rb:45:in
attributes_from_column_definition’
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/base.rb:1505:in
initialize_without_callbacks' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/callbacks.rb:225:in
initialize’
from (irb):2:in `new’
I can’t make sense of this. I’ve updated the database.yml file to:
development:
adapter: mysql
encoding: utf8
database: db/rubytryout_development
username: root
password:
socket: /tmp/mysql.sock
test:
adapter: mysql
encoding: utf8
database: db/rubytryout_test
username: root
password:
socket: /tmp/mysql.sock
production:
adapter: mysql
encoding: utf8
database: db/rubytryout_production
username: root
password:
socket: /tmp/mysql.sock
I’ve installed the MySQL gem to the appropriate mysql directory, and
I’ve verified that the databases exist…any ideas what could be going
on? Seems like it’s not bound correctly, but I can’t for the life of me
figure it out. What am I missing?
I imagine there’s an easy fix, so apologies in advance if this is a
‘dumb newbie’ question. I’m used to running and querying MySQL, but not
installing it or messing around in Unix, so there’s a steep learning
curve here. Especially now that Ruby comes standard on OSX, but is now
bound to SQLite by default.
Thanks for any help you can give.