AWSにはRDSというマネージドリレーショナルデータベースサービスがあり、インストール作業をすることなく簡単にデータベースを使うことが可能です。
しかし、EC2に直接、MySQLをインストールすることも可能です。
Amazon EC2にMySQLをインストールする方法をまとめました。
Amazon EC2にMySQLをインストールする方法
EC2の作成
AWSでEC2インスタンスを作成して起動する
MySQLをyumでインストール
ec2-userでログインする
MySQLをyumでインストールする
$ sudo yum remove -y mariadb-libs
$ sudo yum localinstall -y https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
$ sudo yum install -y --enablerepo=mysql80-community mysql-community-server
$ sudo systemctl enable mysqld.service
システムを再起動してMySQLに接続
システムを再起動する
$ sudo reboot
MySQLが稼働していることを確認する
$ systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2020-10-26 04:13:21 UTC; 1min 32s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 3045 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 3068 (mysqld)
Status: "Server is operational"
CGroup: /system.slice/mysqld.service
└─3068 /usr/sbin/mysqld
MySQLのバージョンを確認する
$ sudo mysql --version
mysql Ver 8.0.22 for Linux on x86_64 (MySQL Community Server - GPL)
MySQLのrootのパスワードを取得する
$ sudo cat /var/log/mysqld.log
以下の行からrootのパスワードを見つける
2020-10-26T04:11:24.975236Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: -OoEfTnJl9cj
MySQLのrootのパスワードでログイン
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.22
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
パスワードを変更する
mysql>alter user 'root'@'localhost' identified by 'PlanBunseki8!';
mysql>quit
再度ログインにする
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.22 MySQL Community Server - GPL
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
これで準備完了です。
コメント