LoginSignup
0
0

More than 1 year has passed since last update.

MariaDB導入

インストール

Amazon Linux 2を利用している場合、MariaDBは 「yumコマンド」からインストールできます

EC2ターミナル
[ec2-user@ip-172-31-25-189 ~]$ sudo yum -y install  mariadb-server mysql-devel

データベースの起動

データベースを起動するにはsystemctlコマンドを利用します

EC2ターミナル
[ec2-user@ip-172-31-25-189 ~]$ sudo systemctl start mariadb

systemctlコマンド:
Amazon LinuxやCentOSに含まれているもので、インストールしたソフトウェアの起動を一括して行えるツールです。

データベースが起動したことを確認します

EC2ターミナル
[ec2-user@ip-172-31-25-189 ~]$ 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 土 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)

「active (running) 」と緑色の表示がされれば、データベースの起動は成功です。

データベースのrootパスワードを設定する

yumでインストールしたMariaDBには、デフォルトで「root」というユーザーでアクセスできるようになっていますが、パスワードは設定されていません。なので、パスワードを設定する必要があります。

EC2ターミナル
[ec2-user@ip-172-31-25-189 ~]$ sudo /usr/bin/mysql_secure_installation

以下の手順で設定します
[1]Enter current password for root (enter for none)
現在のパスワードを入力(なければエンター)
[2]Set root password? [Y/n]
パスワードをセットしますか?Yでエンター
[3]New password:
新しいパスワードを入力してエンター
[4]Re-enter new password:
パスワードを再度入力
[5]Remove anonymous users? [Y/n]
匿名のユーザーを排除しますか?(誰でもログインできないようにしますか?)Yでエンター
[6]Disallow root login remotely? [Y/n]
RootでMySQLにリモートログインをできないようにしますか?という意味
セキュリティ上りモートでログインできるとまずいのでYでエンター
[7]Remove test database and access to it? [Y/n]
テストデータベースとそれのアクセスを排除しますか?Yでエンター
[8]Reload privilege tables now? [Y/n]
権限の変更を即時反映しますか?Yでエンター

データベースへ接続する

EC2ターミナル
[ec2-user@ip-172-31-25-189 ~]$ mysql -u root -p

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)]> 

まとめ

パスワードはこれからも使うことになるのでメモしておきましょう
(一回パスワード忘れて酷い目に遭いました)
データベースの操作方法に関してまた記事を出そうと思います

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0