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: railstest
vi 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
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.
本文出自 “xs笔记” 博客,谢绝转载!
原文地址:http://ikezcn.blog.51cto.com/7051942/1879838