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'

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

数据库相关:
active_record :
https://ruby-china.github.io/rails-guides/active_record_querying.html

posted @   HaimaBlog  阅读(117)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
历史上的今天:
2019-01-10 Vue2.0--14.小白入门教程--实例化多个vue对象,可初始化操作几种方法
2019-01-10 37.VUE学习之-表单的综合运用
点击右上角即可分享
微信分享提示