Create a new Ruby on Rails application using MySQL instead of SQLite

前端 未结 19 1294
难免孤独
难免孤独 2020-12-04 05:46

I want to create my Rails application with MySQL, because I like it so much. How can I do that in the latest version of Rails instead of the default SQLite?

19条回答
  •  悲&欢浪女
    2020-12-04 06:06

    If you have not created your app yet, just go to cmd(for windows) or terminal(for linux/unix) and type the following command to create a rails application with mysql database:

    $rails new -d mysql

    It works for anything above rails version 3. If you have already created your app, then you can do one of the 2 following things:

    1. Create a another_name app with mysql database, go to cd another_name/config/ and copy the database.yml file from this new app. Paste it into the database.yml of your_app_name app. But ensure to change the database names and set username/password of your database accordingly in the database.yml file after doing so.

    OR

    1. Go to cd your_app_name/config/ and open database.yml. Rename as following:

    development:
    adapter: mysql2
    database: db_name_name
    username: root
    password:
    host: localhost
    socket: /tmp/mysql.sock

    Moreover, remove gem 'sqlite3' from your Gemfile and add the gem 'mysql2'

提交回复
热议问题