Rails installs Rails on Ubuntu (RVM Ruby gem Bootstrap bootswatch)
Rails 4.1.4
Ruby 2.2.0
-
sudo apt-get install mysql-server mysql-client installing MySQL (setting up the MySQL user root password during installation)
-
sudo apt-get install Libmysqlclient-dev (HTTPS://GITHUB.COM/BRIANMARIO/MYSQL2 see this section for Linux and other unixes)
-
Mysql-u root-p (log in to MySQL with MySQL root user)
-
Create Database railstest; (CREATE DATABASE)
-
show databases; (View database)
-
Exit (Quit database)
-
Rails new trails-d MySQL
-
CD Trails
-
VI config/database.yml (connection data file, modified to the following)
Default: &default
Adapter:mysql2
Encoding:utf8
Pool:5
Username:root
Password:mysql User root Password
Socket:/var/run/mysqld/mysqld.sock
Development:
<<: *default
Database:railstest
-
VI gemfile (Modify Gem ' mysql2 ')
Gem ' mysql2 ', ' ~> 0.3.20 '
-
Bundle Install (Install the software in Gemfile)
-
Test
ails G Scaffold Product name:string price:decimal description:text (CREATE TABLE)
Rake db:migrate (CREATE TABLE)
Note:
Error: Specified ' MYSQL2 ' for database adapter, but the gem was not loaded. In connection with the MYSQL2 version, refer here 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.
This article is from "XS Notes" blog, declined reprint!
Rails connects to MySQL database running on Ubuntu