ruby on rails converting from sqlite3 to mysql2 gem
My installation
- Ubuntu 10.10
- Rails 3
- gem = sqlite3 and sqlite3-ruby
- gem = mysql2
Now I created a application called mytestapp, using
rails new mytestapp
As usual with rails 3 it defaults to using sqlite3 database. Now I wanted to change the database for mytestapp so that it uses MySql database.
I made changes here
- database.yml
- gemfile - I added gem 'mys开发者_运维问答ql2' and removed gem 'sqlite3'
My new database.yml looked something like this
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: mytestapp_development
pool: 5
username: mytestapp
password: hacked
socket: /var/run/mysqld/mysqld.sock
Now I goto localhost:3000 and click on the about application's development environment I get the following error
ActiveRecord::ConnectionNotEstablished
MySql user mytestapp has proper permissions for the database.
Infact when I create a new rails app using the following
rails new anotherapp -d mysql
It works great. What can be missing here.
Have you ran bundle install
after editing your Gemfile
?
If you did, then try to run the following command to see what's the difference between your hand-edited application and the new you created with -d mysql:
diff /path/to/hand-edited-app /path/to/rails-created-mysql-app
精彩评论