LoginSignup
0
0

More than 1 year has passed since last update.

AWSサービスLightsailのデータベース操作方法

Last updated at Posted at 2021-10-22

AWSサービスLightsail

Amazon Lightsailは、AWSが提供しているVPS(Virtual Private Server:仮想プライベートサーバー)サービスです。

データベースの操作方法

Linux/Unix OSとLAMP(PHP 7)アプリのインスタンスを作成している前提です。

まずは、インスタンスにアクセスします。
ターミナルでもいいしLightsailの管理画面でもOKです。

そこで、下記のコマンドを実行して、データベースのパスワードを調べます。
出てきたパスワードをコピーします。

コマンド
cat bitnami_application_password

スクリーンショット-2021-10-22-18.43.41.png
パスワードがわかったら、mysqlコマンドを使ってアクセスします。

コマンド
mysql -u root -p

先ほど、入手したパスワードをペーストします。
入れない場合は入力して見てください。

スクリーンショット-2021-10-22-18.52.13.png

rootパスワードを変更する方法

コマンド
MariaDB [(none)]> update mysql.user set password=password('新しいパスワード') where user = 'root'; flush privileges;

ユーザーを作成する方法

「wordpress」というユーザーを「mypassword」というパスワードで作成します。

コマンド
MariaDB [(none)]> create user 'wordpress'@'localhost' IDENTIFIED BY 'mypassword';

データベース作成方法

入ったら、下記のコマンドを実行して作成します。
「DB_NAME」はデータベースの名前です。

コマンド
MariaDB [(none)]> create database DB_NAME;

データベース確認方法

下記のコマンドでデータベース一覧が確認出来ます。

コマンド
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| DB_NAME             |
| test               |
+--------------------+

データベース権限設定方法

コマンド
MariaDB [ (none)]> grant all privileges on DB_NAME.* to 'wordpress'@'localhost' FLUSH PRIVILEGES;

データベースをSSHでダンプする方法

コマンド
mysqldump --single-transaction -u bn_wordpress -p -h 127.0.0.1 -P 3306 bitnami_wordpress > /opt/bitnami/apps/wordpress/htdocs/bitnami_wordpress.sql
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