06. rails gem 安装mysql

修改Gamefile

Gamefile 里添加 gem 'mysql2'

执行命令行

bundle

可以看到下图片上已经安装好依赖了

修改配置文件

修改config/database.yml文件

# SQLite. Versions 3.8.0 and up are supported.
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
#default: &default
 # adapter: sqlite3
 # pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
 # timeout: 5000

##添加msyql的配置
default: &default
  adapter: mysql2
  encoding: utf8mb4
  pool: 5
  host: 127.0.0.1
  username: root
  password: 123456


development:
  <<: *default
  #database: db/development.sqlite3
  database: circles_development  #数据库的名称

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  #database: db/test.sqlite3
  database: circles_test

production:
  <<: *default
  #database: db/production.sqlite3
    database: circles_production

查看rake使用命令

rake -T #查看命令

创建数据库

haima@haima-PC:/media/haima/34E401CC64DD0E28/site/go/src/ruby/circles$ rake db:create
Created database 'circles_development'
Created database 'circles_test'

下图可以看到已经创建了两个数据库

原文地址:https://www.cnblogs.com/haima/p/14259449.html