Rails安裝好 Rails 在ubuntu上安裝rails(rvm ruby gem Bootstrap bootswatch)
rails 4.1.4
ruby 2.2.0
sudo apt-get install mysql-server mysql-client 安裝mysql(安裝過程中設置mysql用戶root密碼)
sudo apt-get install libmysqlclient-dev (https://github.com/brianmario/mysql2 看這段說明Linux and other Unixes)
mysql -u root -p (用mysql的root用戶登錄mysql)
create database railstest; (創建數據庫)
show databases; (查看數據庫)
exit (退出數據庫)
rails new trails -d mysql
cd trails
vi config/database.yml (連接數據的文件,修改爲以下)
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password: mysql用戶root密碼
socket: /var/run/mysqld/mysqld.sock
development:
<<: *default
database: railstestvi Gemfile (修改gem 'mysql2')
gem 'mysql2','~> 0.3.20'
bundle install (安裝Gemfile裏的軟件)
測試
ails g scaffold product name:string price:decimal description:text (創建表)
rake db:migrate (創建表)
備註:
報錯:Specified 'mysql2' for database adapter, but the gem is not loaded.與mysql2的版本有關,參考這裏https://github.com/brianmario/mysql2
Ruby on Rails / Active Record
mysql2 0.4.x works with Rails / Active Record 4.2.5 - 5.0 and higher.
mysql2 0.3.x works with Rails / Active Record 3.1, 3.2, 4.x, 5.0.
mysql2 0.2.x works with Rails / Active Record 2.3 - 3.0.