February 5, 2011
Getting Rails 3.0.3 running with Mysql
Just as a memory aid for me and though I can share this.
While experimenting the Ruby on Rails 3.0.3, I created an application that by default uses SQLite, but I want to use MySql instead.
So here the steps I gone through:
1) Install MySql Server
sudo apt-get install mysql-server
2) Install MySql client dev package
sudo apt-get install libmysqlclient-dev
3) Create a new mysql user to use during my development and tests
3.1 ) Connect to mysql
mysql -u root -p
3.2 Create a user
create user 'railsuser'@'localhost' identified by 'somepass';
3.3) Grant all privileges to the user, so rails can do everything for me, such as creating the databases:
grant all privileges on *.* to 'railsuser'@'localhost';
4) Edit my app Gemfile:
Comment, or remove, the following line
gem 'sqlite3-ruby', :require => 'sqlite3'
Add this line:
5) Run the Bundler tool, the dependency management tool for Rails app:
sudo bundle install
Hopefully, everything went just fine till here.
Now, just configure my database.yml to use MySql as a database:
development: adapter: mysql2 encoding: utf8 reconnect: false database: myapp_development pool: 5 username: railsuser password: somepass socket: /var/run/mysqld/mysqld.sock test: adapter: mysql2 encoding: utf8 reconnect: false database: myapp_test pool: 5 username: railsuser password: railsuser1234 socket: /var/run/mysqld/mysqld.sock
For production, just use the MySql user that I want in production.
6) Let rake create my databases, by running: