Amazon LightsailでMySQLデータベースを使う
![](https://www13.a8.net/0.gif?a8mat=35D1T5+3BO5DE+50+2HLY9D)
データベースを作る
![](https://www.blog.danishi.net/wp-content/uploads/2019/07/image-11-1024x551.png)
データベースタブからデータベースの作成を選択します。
![](https://www.blog.danishi.net/wp-content/uploads/2019/07/image-12-1024x677.png)
DBMSはMySQL(5.6.44、5.7.26、8.0.15)とPostgreSQL(9.6.14、10.9、11.4)が選べます。
![](https://www.blog.danishi.net/wp-content/uploads/2019/07/image-13-1024x316.png)
データベースのログインユーザとパスワード、データベース名を設定できます。
特に指定しなければAWSがよしなに設定してくれます。
![](https://www.blog.danishi.net/wp-content/uploads/2019/07/image-14-1024x670.png)
データベースプランを選択できます。
最小構成は最初の1ヵ月が無料です。
高可用性モードにすると料金が2倍になりますが、別のAZにセカンダリデータベースを作成してくれます。
![](https://www.blog.danishi.net/wp-content/uploads/2019/07/image-15-1024x700.png)
Lightsail内でのリソース識別名を付けたらデータベースが作成できます。
![](https://www.blog.danishi.net/wp-content/uploads/2019/07/image-16-1024x396.png)
5分そこら待つとデータベースが出来上がります。
データベースを使う
![](https://www.blog.danishi.net/wp-content/uploads/2019/07/キャプチャ-1-1024x654.png)
管理ページから接続情報を確認できます。
デフォルトだと、Lightsailリソースからのみアクセスできます。
Lightsailのインスタンスにログインし、ユーザー名とパスワード、エンドポイントを使ってアクセスしてみます。
$ mysql -u dbmasteruser -p -h エンドポイント
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.26-log Source distribution
Copyright (c) 2000, 2018, 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>
パブリックモードでアクセスする
![](https://www.blog.danishi.net/wp-content/uploads/2019/07/image-17-1024x328.png)
パブリックモードを有効にすると、インターネット経由でアクセスすることができます。
この状態だとユーザーとパスワードを知っていればアクセスできるため管理には気を付けましょう。
ローカルのMySQL Workbenchでアクセスしてみます。
![](https://www.blog.danishi.net/wp-content/uploads/2019/07/image-18-1024x642.png)
![](https://www.blog.danishi.net/wp-content/uploads/2019/07/image-19-1024x623.png)
簡単なステップですぐに構築でき、固定の料金のLightsailはやっぱり便利ですね。
インターネットアクセスできるRDBを簡単に建てれるのは、一時的にオフショア、ニアショアする開発案件とかで便利そうです。
でわ。
ディスカッション
コメント一覧
まだ、コメントがありません