Rails Database setup is set in the file config/database.yml. By default its sqlite, which is a database system that puts the entire database in a file and uses 1-to-1 connection.

Rails supports the MySQL (MariaDB) database system, which is what you want to be using in web apps. PostgreSQL is also supported.

Rails Database

Install MySQL

The apt-get command is a tool for Ubuntu Linux. You may need tool yum, brew or whichever tool your operating system provides.

Install MySQL server and additional files:

apt-get install mysql-server
apt-get install libmysqlclient-dev

In your project directory:

gem install 'mysql2'
gem install 'activerecord-mysql2-adapter'

Configure MySQL

If the MySQL database system is not installed, install it first.
Remove the lines in config/database.yml. Then add the config below:

   adapter: mysql2
   database: library_development
   username: root
   password: [password]
   host: localhost

   adapter: mysql2
   database: library_test
   username: root
   password: [password]
   host: localhost

   adapter: mysql2
   database: library_production
   username: root
   password: [password]
   host: localhost

Change [password] to your MySQL password.

Create Databases

Create the databases. Start MySQL in the terminal with mysql -u root -p. Then type these commands:

mysql> CREATE DATABASE library_development;
mysql> CREATE DATABASE library_production;
mysql> CREATE DATABASE library_test;

MySQL will reply:

Query OK, 1 row affected (0.00 sec)

If you type the command:

mysql> show databases;

It shows the databases have been created.