そろばんのしょ(第3版第2刷)

雑魚い見習いDBAの日々学んだことや、どーでもいいことを。基本は自分の備忘録。

MySQLでユーザーを作ったときのハッシュ値から同じ`PASSWORD`でユーザーを生成する

MySQL5.7の話。本日隣の人から教えてもらった事。

ユーザーを作るとき等でAPサーバーのIPが追加や変更されるときにハッシュ値から同じパスワードを設定することができる。

例えば、

fuki [(none)]> create user 'fuki'@'127.0.0.1' identified by 'Abc123';
Query OK, 0 rows affected (0.07 sec)

fuki [(none)]> SELECT user,host,authentication_string FROM mysql.user WHERE user='fuki' ORDER BY 1,2;
+------+-----------+-------------------------------------------+
| user | host      | authentication_string                     |
+------+-----------+-------------------------------------------+
| fuki | 127.0.0.1  | *7A8BBCB18A250055A6BB98ECFA33A8174D219504 |
+------+-----------+-------------------------------------------+
1 rows in set (0.00 sec)

上記のようなfukiを作るとパスワードはauthentication_stringにあるようなハッシュ値になる。 このハッシュ値を利用してユーザーを再作成するときはIDENTIFIED BYのあとにPASSWORDをつける。

mysql [(none)]> create user 'fuki'@'localhost' identified by password '*7A8BBCB18A250055A6BB98ECFA33A8174D219504';
Query OK, 0 rows affected, 1 warning (0.00 sec)

Warning (Code 1287): 'IDENTIFIED BY PASSWORD' is deprecated and will be removed in a future release. Please use IDENTIFIED WITH <plugin> AS <hash> instead
mysql [(none)]> SELECT user,host,authentication_string FROM mysql.user WHERE user='fuki' ORDER BY 1,2;
+------+-----------+-------------------------------------------+
| user | host      | authentication_string                     |
+------+-----------+-------------------------------------------+
| fuki | 127.0.0.1 | *7A8BBCB18A250055A6BB98ECFA33A8174D219504 |
| fuki | localhost | *7A8BBCB18A250055A6BB98ECFA33A8174D219504 |
+------+-----------+-------------------------------------------+
2 rows in set (0.00 sec)

同じハッシュ値になっている。

しかし、Warningにもあるようにいずれなくなる機能のようである。 まあ、普通に作成しろってことですよね。