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

前端 未结 19 1190
难免孤独
难免孤独 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:23

    Go to the terminal and write:

    rails new <project_name> -d mysql
    
    0 讨论(0)
  • 2020-12-04 06:24

    Use following command to create new app for API with mysql database

    rails new <appname> --api -d mysql
    
    
      adapter: mysql2
      encoding: utf8
      pool: 5
      username: root
      password: 
      socket: /var/run/mysqld/mysqld.sock
    
    0 讨论(0)
  • 2020-12-04 06:28

    On new project, easy peasy:

    rails new your_new_project_name -d mysql
    

    On existing project, definitely trickier. This has given me a number of issues on existing rails projects. This kind of works with me:

    # On Gemfile:
    gem 'mysql2',  '>= 0.3.18', '< 0.5' # copied from a new project for rails 5.1 :)
    gem 'activerecord-mysql-adapter' # needed for mysql..
    
    # On Dockerfile or on CLI:
    sudo apt-get install -y  mysql-client libmysqlclient-dev 
    
    0 讨论(0)
  • 2020-12-04 06:30
    rails -d mysql ProjectName
    
    0 讨论(0)
  • 2020-12-04 06:30

    Create application with -d option

    rails new AppName -d mysql
    
    0 讨论(0)
  • 2020-12-04 06:30

    Just go to rails console and type:

    rails new YOURAPPNAME -d mysql
    
    0 讨论(0)
提交回复
热议问题