web-dev-qa-db-ja.com

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

$ mysql -u root -pを使用してログインし、データベースを表示したときに何かがおかしくなる前に、

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

それから私は新しいユーザーを作成しようとしましたが、PRIVILEGESに何か問題があることに気づきました。

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

それから私は再び「root」を作成しようとしますが、すべての特権を付与するときにAccess deniedエラーを取得します。

mysql> CREATE USER 'root'@'localhost' IDENTIFIED BY 'password';
mysql> grant all privileges on *.* to 'root'@'localhost' identified by 'password' with grant option;
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

$ mysql -u root -pを使用してMySQLに再度ログインし、データベースを表示すると、

+--------------------+
| Database           |
+--------------------+
| information_schema |
+--------------------+

他のデータベースはすべてなくなりました。

MySQLを今すぐ修正するにはどうすればよいですか?

データベース 'mysql'が見つからない、データベースを作成できない、ユーザーを作成できない、などとするとエラーが発生します。

エラー1045(28000):ユーザー 'root' @ 'localhost'のアクセスが拒否されました(パスワードを使用:YES)。

MacPortを使ってMySQLを再インストールする必要がありますか?再インストールすると、データベースgame_dataを失うことになりますね。

116
Vogelsire

以下の手順に従ってください。

  1. MySQLサーバインスタンスまたはデーモンを--skip-grant-tablesオプション(セキュリティ設定)で起動します。

    $ mysqld --skip-grant-tables
    
  2. これらのステートメントを実行してください。

    $ mysql -u root mysql
    $mysql> UPDATE user SET Password=PASSWORD('my_password') where USER='root';
    $mysql> FLUSH PRIVILEGES;
    

あなたが上記の未知のフィールドパスワードエラーに直面した場合:

update user set authentication_string=password('my_password') where user='root';
  1. 最後に、--skip-grant-tablesオプションを指定せずにインスタンス/デーモンを再起動します。

    $ /etc/init.d/mysql restart
    

これで新しいパスワードで接続できるはずです。

$ mysql -u root -p

パスワードを入力してください:my_password

MySQLの“ Unable to lock ibdata1”エラーを修正

Sudo mv /usr/local/mysql/data/ibdata1 /usr/local/mysql/data/ibdata1.bak
Sudo mv /usr/local/mysql/data/ib_logfile0 /usr/local/mysql/data/ib_logfile0.bak
Sudo mv /usr/local/mysql/data/ib_logfile1 /usr/local/mysql/data/ib_logfile1.bak
Sudo cp -a /usr/local/mysql/data/ibdata1.bak /usr/local/mysql/data/ibdata1
Sudo cp -a /usr/local/mysql/data/ib_logfile0.bak /usr/local/mysql/data/ib_logfile0
Sudo cp -a /usr/local/mysql/data/ib_logfile1.bak /usr/local/mysql/data/ib_logfile1
Sudo /etc/init.d/mysql restart
127
Yogus

上記のどれも私にとって役に立ちませんでした。プラグインメソッドをクリアする必要があることがわかりました。 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;

Docsによると、プラグインを空の文字列に設定すると、事実上mysql_native_passwordにデフォルト設定されているはずですが、空のパスワードハッシュによって混乱するかもしれません。よりニュアンスのために、あなたはここでドキュメンテーションを読むことができます: https://dev.mysql.com/doc/refman/5.7/en/native-authentication-plugin.html

58

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

バージョン5.5.7以降、mysqlはさまざまな認証プラグインをサポートしています 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
d9k
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サーバー配備の保護.

Enter password for user root: 

The existing password for the user account root has expired. Please set a new password.

New password: 

Re-enter new password:

あなたが見るならそれは言う

... Failed! Error: Your password does not satisfy the current policy requirements
That means your password needs to have a character such as ! . # - etc...
mix characters well, upper case, lower case, ! . , # etc...

New password: 

Re-enter new password: 
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

Estimated strength of the password: 100 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : Y

New password: 

Re-enter new password: 

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.

All done! 
[root@SERVER ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.10 MySQL Community Server (GPL)

このビデオの最後の10分 を見てください

7
Tadeh

それを試してみてください:

mysql --no-defaults --force --user=root --Host=localhost --database=mysql 
UPDATE user SET Password=PASSWORD('NEWPASSWORD') where USER='root';
FLUSH PRIVILEGES;
3
Gustavo Duarte

私の場合、データベースが破損しています。Debianでmysqlを再起動した後、rootログインはパスワードなしでした。解決策はこれでした:

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

他にもnative_passwordプラグインについての回答がありますが、これは複雑な手間をかけずに実行できる方法です。それはそれが変更されることを意味している方法です。

2
John