2017-02-14

MySQLでユーザーに設定したパスワードが効かなくて嵌った件

Amazon Linuxでyumを使ってMySQL56をインストールし起動し、データベースとユーザーを作成して
ログインしてみると設定したパスワードでログインできないではありませんか(;゜〇゜)

mysql> create database mydb character set utf8;
mysql> grant all on mydb.* to user identified by 'xxxxx';

$ mysql -u user -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'user '@'localhost' (using password: YES)

ところが、パスワードなしでログインを試みるとは入れてしまいましたΣ(゜д゜;)

プロセスを確認してみると指定したユーザーでログインしています。

$ mysql -u user
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 30
Server version: 5.6.35 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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 processlist;
+----+-----------+-----------+------+---------+------+-------+------------------+
| Id | User  | Host      | db   | Command | Time | State | Info  |
+----+-----------+-----------+------+---------+------+-------+------------------+
| 28 | user      | localhost | NULL | Query   |    0 | init  | show processlist |
+----+-----------+-----------+------+---------+------+-------+------------------+
1 row in set (0.00 sec)

ユーザーテーブルどーなってるか確認してみるとユーザー名なし、パスワードなしの登録が入っていました

あやしいです(;一_一)

mysql> select user,host from user;
+-----------+------------------+-------------------------------------------+
| user     | host        | password       |
+-----------+------------------+-------------------------------------------+
| user      | %         | *XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
| root     | 127.0.0.1        |                                           |
| root     | ::1        |                                           |
|     | ip-xxx-xx-xx-xxx |                                           |
| root     | ip-xxx-xx-xx-xxx |                                           |
|     | localhost        |                                           |
| root     | localhost        |                                           |
+-----------+------------------+-------------------------------------------+

mysql> select host from user where user="";
+------------------+
| host     |
+------------------+
| ip-xxx-xx-xx-xxx |
| localhost    |
+------------------+
2 rows in set (0.00 sec)

怪しいので消してしまいましょうヽ(´ー`)/
mysql> delete from user where user="";
Query OK, 2 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

そしたら、次の通り入れました!ヾ(*・∀・)ノ"
$ mysql -u user -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 30
Server version: 5.6.35 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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> 

0 件のコメント:

コメントを投稿