<< All Posts
Starting a new Rails project using MySQL

Starting a new Rails projects starts basically having Rails installed. If you don’t have it yet, you can install with:

gem install rails

If you want to check the version of rails you have, try:

rails --version

Having Rails now it’s time to create your project using MySQL instead of the default option which is SQLite.

rails new ProjectName -d mysql

Now that we have our project, we’re going to just change the file database.yml adding the password. Keep in mind that in production environment, you won’t do this. The best practice says to setup credentials as Config Variables.

vim config/database.yml

And add the password on this section:

default: &default
  adapter: mysql2
  encoding: utf8
  pool: 5
  username: root
  socket: /var/run/mysqld/mysqld.sock

The last step is create the database. Rails is going to create a development and test database:

bundle exec rake db:create

That’s it!

<< All Posts


🇧🇷 🇨🇦
Runs on OpenBSD 🐡