[RUBY] Create a database in a production environment

Introduction

The procedure for "using the AWS server" is written in 5 parts.

Please check the articles below.

Initial setting of EC2Create a database in the production environment ← Imakoko ③ Start Rails on EC2Set up the Web serverAutomate deployment

Database preparation

There are the following types of databases.

・ Hierarchical database ・ Network database ・ Relational database

The most used of these is the relational database Information can be organized and managed in the form of an Excel table. And the software that manages this relational database It is called ** Relational Database Management System (RDBMS) **.

One of the representative RDBMS is MySQL And there is also a database called MariaDB derived from MySQL.

"MariaDB" is open source software developed as a derivative of MySQL. Compatible with MySQL. Amazon Linux 2 is supposed to use MariaDB.

Install MariaDB

If you are using Amazon Linux 2, MariaDB can be installed from the "yum command".

Execute the following command in the terminal (in EC2)

[[email protected]***-**-**-*** ~]$ sudo yum -y install mysql56-server mysql56-devel mysql56 mariadb-server mysql-devel

Start database

Use the "systemctl command" to start the database.

Execute the following command in the terminal (in EC2)

[[email protected]***-**-**-*** ~]$ sudo systemctl start mariadb

Execute the following command to check if it can be started

[[email protected]***-**-**-*** ~]$ sudo systemctl status mariadb

● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
   Active: active (running)since Sat 2020-02-29 07:00:11 UTC; 7s ago
  Process: 5993 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
  Process: 5957 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)

If "active (running)" is displayed in green, the database startup is successful.

Setting the database root password

MariaDB installed with yum has the default user "root" You can access it, but no password has been set. You need to set a password.

Execute the following command in the terminal (in EC2)

[[email protected]***-**-**-*** ~]$ sudo /usr/bin/mysql_secure_installation

Then follow the steps below

① When "Enter current password for root (enter for none):" is displayed, press the Enter key. ② When "Set root password? [Y / n]" is displayed, enter "Y" and press the Enter key. ③ When "New password:" is displayed, enter the password you decided (* Nothing is displayed on the screen, but you can enter it) ④ When "Re-enter new password:" is displayed, enter the same password (especially nothing is displayed on the screen, but you can enter it)

If "... Success!" Is displayed here, the password setting is complete. It is necessary to continue answering about detailed settings.

⑤ When "Remove anonymous users? [Y / n]" is displayed, enter "Y" and press the Enter key. ⑥ When "Disallow root login remotely? [Y / n]" is displayed, enter "Y" and press the Enter key. ⑦ When "Remove test database and access to it? [Y / n]" is displayed, enter "Y" and press the Enter key. ⑧ When "Reload privilege tables now? [Y / n]" is displayed, enter "Y" and press the Enter key.

Settings are complete when prompted

Check connection to database

Check if the password you set earlier can be used

Execute the following command in the terminal (in EC2)

[[email protected]***-**-**-*** ~]$ mysql -u root -p

You will be prompted to enter the password, "Enter password:". Enter the password you set earlier and press Enter. If the following is displayed, the database settings are complete.

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 142
Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

You can exit by typing "exit".


that's all. Thank you for your hard work.

Continue → here

Recommended Posts

Create a database in a production environment
[Rails] Reset the database in the production environment
How to create a Java environment in just 3 seconds
Create a MySQL test environment (+ millions of test data) in 5 minutes
Create a Vue3 environment with Docker!
Create a new app in Rails
Create a Servlet program in Eclipse
Create a clear time ranking in Firebase's Realtime Database (Android app)
[Rails] How to execute "rails db: create" etc. in production environment EC2
Install Rails in the development environment and create a new application
[Rails] How to reset the database in production environment (Capistrano version)
Create a web environment quickly using Docker
How to reflect seeds.rb in production environment
Building a Lambda development environment in Eclipse
Create a MySQL environment with Docker from 0-> 1
Let's create a Java development environment (updating)
Create a TODO app in Java 7 Create Header
Creating a Servlet in the Liberty environment
Image is not displayed in production environment
Take a thread dump in a JRE environment
Display the background image in the production environment
To create a Zip file while grouping database search results in Java
Try to create a browser automatic operation environment using Selenide in 5 minutes
How to create a database for H2 Database anywhere
[Memo] Create a CentOS 8 environment easily with Docker
Create a Privoxy + Tor environment instantly using Docker
Create a CSR with extended information in Java
[Rails] rails new to create a database with PostgreSQL
[Windows] [IntelliJ] [Java] [Tomcat] Create a Tomcat9 environment with IntelliJ
Create a simple batch processing framework in Eclipse.
[Android / Java] Operate a local database in Room
rails tutorial About account activation in production environment
Rails5.1 + puma SSL connection in local production environment
Try to create a bulletin board in Java
Let's create a custom tab view in SwiftUI 2.0
Let's create a super-simple web framework in Java
Delete all records in a MySQL database table
How to create a theme in Liferay 7 / DXP
Create a tool for name identification in Salesforce
How to easily create a pull-down in Rails
500 Internal Server Error occurs in Rails production environment
Create a docker environment for Oracle 11g XE
Create a native extension of Ruby in Rust
Create a Spring Boot development environment with docker
(Capistrano) After deploying, I get a We're sorry… error in the production environment.
Create a Java development environment using jenv on Mac
3. Create a database to access from the web module
[Java] Create a filter
How to create a JDBC URL (Oracle Database, Thin)
How to create a Spring Boot project in IntelliJ
Let's create a gcloud development environment on a centos8 container
Java / Twitter clone / task management system (1) Create a database
I tried to create a Clova skill in Java
How to create a data URI (base64) in Java
Verification value error that occurred in a clustering environment
[Note] Build a Python3 environment with Docker in EC2
[Note] Create a java environment from scratch with docker
Create JSON in Java
Create a Java, JavaScript team development environment (problem raising)
[Programming complete] §5 Create a review management app in Ruby
Production environment and credentials.yml.enc