Using MySQL with Ruby on Rails
Posted on 2008-10-03
I downloaded the latest version of Ruby which now uses sqlite 3 for its default database. I need to use MySQL. I created a folder for my first app and then ran the following command:
This created a folder in my appfolder called first. I then created a new controller named Hello like this in the command line:
appfolder>first>ruby script/generate controller Hello
I then started up WEBrick and navigated my browser to /localhost:3000/hello. I was supposed to see Unknown action: no action responded to index. I instead got an error. The title was "MissingSourceFile in HelloController#index" with an error message "no such file to load -- sqlite3".
This is when I realized that I needed to change the default somehow. I changed my database.yml file by running $rails -d mysql temp and copying and pasting the yml file in the temp folder into the yml file in my "first" folder. I then got this error message.
Access denied for user 'root'@'localhost' (using password: YES)
Which used to say (using password: NO) until I change my password to NO. The database.yml for MySQL states to gem install MySQL, which I did, and then "put its /bin directory on your path", but I'm not sure what path that is.
One more thing, the Wrox book I'm using to learn Ruby states that controllers directory is here:
When its actually here:
Finally, I cannot get to mysql from my shell. This:
shell> mysql -u root test
'mysql' is not recognized as an internal or external command, operable program or batch file.
I can only access mysql from the command line by using the MySQL command line client.
How do I connect to MySQL using Rails????