MySQLサーバーへのログイン方法
・sudo mysqlでMySQLサーバーのrootアカウントでログインする
・quitで終了する
ubuntu@i-11100000125436:~$ sudo mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.05 sec)
mysql> quit
Bye
データベースと専用ユーザーの作成
データベースの作成
・CharacterSetは絵文字も利用出来るutf8mb4を利用しましょう
・Collateは絵文字の判別も出来るutf8mb4_binがお薦めです
mysql> CREATE DATABASE wptest DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
Query OK, 1 row affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| wptest |
+--------------------+
5 rows in set (0.01 sec)
ユーザーの作成
mysql> CREATE USER 'wptest_user'@'localhost' IDENTIFIED BY 'hogehogepassword';
Query OK, 0 rows affected (0.02 sec)
mysql> GRANT ALL PRIVILEGES ON wptest.* TO 'wptest_user'@'localhost' WITH GRANT OPTION;
Query OK, 0 rows affected (0.01 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
1行目
‘wptest_user’@’localhost’ | wptest_userという名前のでローカルホスト(このサーバー内)から接続するユーザー |
‘hogehogepassword’ | このユーザーのパスワード |
2行目
ALL PRIVILEGES | 全ての権限 |
wptest.* | wptestデータベース内の全てのテーブルを操作可能 |
WITH GRANT OPTION | 他のユーザーに権限付与可能 |
つまりwptestテーブルに対しての全操作が可能で、例えば外部の人間にSELECT権限のみのユーザーを使用させたい時に、そういったユーザーの作成も可能であるユーザーです。
3行目
FLUSH PRIVILEGES | MySQLサーバーに設定を反映します |
作成したユーザーでログインしてみよう
ubuntu@i-11100000125436:~$ mysql -u wptest_user -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| wptest |
+--------------------+
2 rows in set (0.01 sec)
show databasesで確認出来るデータベースがwptestのみである事が分かります。
information_schemaはスキーマ情報(要はwptestデータベースの情報)が格納されているMySQL側の管理データベースなので気にしないで下さい。
ver5.5くらい?(覚えてない)から必ず付与されるようになったのですが、昔はこれが自動付与されなかったのでマイグレーション用に自分で付与する感じで面倒臭かったのだけは覚えてる。
ここまでの作業でwp_config.phpに設定するデータベースの準備は整いました。
お疲れさまでした。
コメント