2013-06-03 07:32:18 +0000 2013-06-03 07:32:18 +0000
130
130
Advertisement

mysqlどのようにユーザー'root'@'localhost'のために拒否されたアクセスを修正するには

Advertisement

私は何かをねじ込む前に、私は$ mysql -u root -pを使用してログインし、データベースを表示するとき:

+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| game_data |
| test |
+--------------------+

その後、私は新しいユーザーを作成しようとしたし、特権で何かが間違っていることに気づく。

だから私は新しいユーザーを削除し、私は誤って'root'と'Admin'を削除したと思います。

その後、再度'root'を作成しようとしたのですが、全ての権限を付与する際にAccess deniedエラーが出てしまいます。

今、MySQLを修正するには?

データベース ‘mysql’ が見つからない、データベースを作成できない、ユーザーを作成できない、何をしようとしてもエラーが出る

ERROR 1045 (28000). Access denied for user ‘root’@‘localhost’ (using password: YES).

MacPortsを使用してMySQLを再インストールする必要がありますか?再インストールするとデータベースが無くなってしまいますよね?

Advertisement
Advertisement

回答 (6)

138
138
138
2013-06-03 07:35:27 +0000

以下の手順に従ってください。MySQLサーバインスタンスまたはデーモンを--skip-grant-tablesオプション(セキュリティ設定)で起動します。これらのステートメントを実行します。

あなたが上記の不明なフィールドパスワードエラーに直面した場合、使用します:

update user set authentication_string=password('my_password') where user='root';

1.最後に、インスタンス/デーモンを再起動します。最後に、--skip-grant-tablesオプションなしでインスタンス/デーモンを再起動します。

あなたは今、あなたの新しいパスワードで接続することができるはずです。

74
74
74
2016-09-28 15:01:12 +0000

上記のどれも私には参考になりませんでした。プラグインメソッドをクリアする必要があることがわかりました。5.6では、私は行うことができました:

sudo mysql -u root
use mysql;
[mysql] update user set plugin='' where User='root';
[mysql] flush privileges;

5.7では、私は私が必要であることがわかりました:

sudo mysql -u root
use mysql;
[mysql] update user set plugin='mysql_native_password' where User='root';
[mysql] flush privileges;

ドキュメントによると、空の文字列にプラグインが設定されていると、それは効果的にmysqlnativepasswordにデフォルトされているはずですが、空のパスワードハッシュによって混乱している可能性があります。より多くのニュアンスについては、ここでドキュメントを読むことができます。 https://dev.mysql.com/doc/refman/5.7/en/native-authentication-plugin.html

8
Advertisement
8
8
2016-04-28 21:27:58 +0000
Advertisement

また、テーブルuserの必要なレコードが空のpluginフィールドを持っていることを確認してください(例えば、"unix_socket"があることができます)。

バージョン5.5.7以降のバージョン5.5.7 mysqlは様々なauthプラグインのサポートを持っています https://dev.mysql.com/doc/refman/5.6/en/authentication-plugins.html

だから、あなたが空でないpluginフィールドを持っている場合、パスワードは無視され、mysqlエラーログで警告があるでしょう(私のためにそれは/var/log/mysql/error.logです):

[Warning] 'user' entry 'root@localhost' has both a password and an authentication plugin specified. The password will be ignored.

8
8
8
2016-01-22 23:08:02 +0000
grep 'temporary password' /var/log/mysqld.log
Sort date (newest date)

あなたはこのようなものが表示される場合があります;

[root@SERVER ~]# grep 'temporary password' /var/log/mysqld.log
2016-01-16T18:07:29.688164Z 1 [Note] A temporary password is generated for root@localhost: O,k5.marHfFu
2016-01-22T13:14:17.974391Z 1 [Note] A temporary password is generated for root@localhost: b5nvIu!jh6ql
2016-01-22T15:35:48.496812Z 1 [Note] A temporary password is generated for root@localhost: (B*=T!uWJ7ws
2016-01-22T15:52:21.088610Z 1 [Note] A temporary password is generated for root@localhost: %tJXK7sytMJV
2016-01-22T16:24:41.384205Z 1 [Note] A temporary password is generated for root@localhost: lslQDvgwr3/S
2016-01-22T22:11:24.772275Z 1 [Note] A temporary password is generated for root@localhost: S4u+J,Rce_0t
[root@SERVER ~]# mysql_secure_installation

MySQL サーバーの展開を確保します。

3
Advertisement
3
3
2017-11-10 20:13:46 +0000
Advertisement

私の場合、データベースが壊れていて、Debian で mysql を再起動した後、root ログインがパスワードなしになっていました。解決策は次のようになりました:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'test';

いくつかの他の回答では、ネイティブの_passwordプラグインにも言及していますが、これは複雑ないじくり回しをせずにそれを行うことができる方法です。このように変更されることを意味しています。

3
3
3
2014-02-21 17:05:47 +0000

試してみてください:

mysql --no-defaults --force --user=root --host=localhost --database=mysql 
UPDATE user SET Password=PASSWORD('NEWPASSWORD') where USER='root';
FLUSH PRIVILEGES;
Advertisement

関連する質問

15
12
8
2
4
Advertisement