MySQLを5.6から5.7にアップグレードした後、rootユーザーとしてログインできません。

MySQLを5.6から5.7にアップグレードした後、rootユーザーとしてログインできません。

MySQLを5.6から5.7にアップグレードした後、rootとしてログインできません。

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

ログに次のものが見つかりました。

2016-10-26T10:23:01.845088Z 0 [Warning] User entry 'root'@'localhost' has an empty plugin value. The user will be ignored and no one can login with this user anymore.
2016-10-26T10:23:01.845112Z 0 [Warning] User entry 'mysql.sys'@'localhost' has an empty plugin value. The user will be ignored and no one can login with this user anymore.
2016-10-26T10:23:01.845127Z 0 [Warning] User entry 'debian-sys-maint'@'localhost' has an empty plugin value. The user will be ignored and no one can login with this user anymore.
2016-10-26T10:23:01.845142Z 0 [Warning] User entry 'phpmyadmin'@'localhost' has an empty plugin value. The user will be ignored and no one can login with this user anymore.
2016-10-26T10:23:01.845155Z 0 [Warning] Some of the user accounts with SUPER privileges were disabled because of empty mysql.user.plugin value. If you are upgrading from MySQL 5.6 to MySQL 5.7 it means we were not able to substitute for empty plugin column. Probably because of pre 4.1 password hash. If your account is disabled you will need to:
2016-10-26T10:23:01.845183Z 0 [Warning] 1. Stop the server and restart it with --skip-grant-tables.
2016-10-26T10:23:01.845192Z 0 [Warning] 2. Run mysql_upgrade.
2016-10-26T10:23:01.845200Z 0 [Warning] 3. Restart the server with the parameters you normally use.
2016-10-26T10:23:01.845207Z 0 [Warning] For complete instructions on how to upgrade MySQL to a new version please see the 'Upgrading MySQL' section from the MySQL manual
2016-10-26T10:23:01.853461Z 0 [Note] Event Scheduler: Loaded 0 events
2016-10-26T10:23:01.853962Z 0 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.7.16-0ubuntu0.16.04.1'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Ubuntu)
2016-10-26T10:23:02.138961Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO)

だから提案した通りにしました。サーバーを停止します。

> service mysql stop

承認フォームをスキップして開始します。

> sudo mysqld_safe --skip-grant-tables

mysqld_safe が --skip-grant-tables と一緒に実行されると、rootとしてログインできますが、実行中の端末を閉じる前にのみ可能です(デーモンとしては実行されませんが、端末が閉じると停止します)。

その後、提案されているようにmysql_upgradeを実行しました(他の端末で)。

> sudo mysql_upgrade

これは私の机をアップグレードしました。

mysqld_safeを実行している端末を閉じてmysqlサーバーを停止しました(service mysql stop)。 mysqlのすべてのインスタンスを終了する必要があります。それ以外の場合は、次のエラーの完全なログが表示されます。

2016-10-26T10:40:54.073975Z 0 [ERROR] InnoDB: Unable to lock ./ibdata1 error: 11
2016-10-26T10:40:54.074060Z 0 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.

その後、MySQLを再起動します。

> service mysql start

上記と同じ結果が得られました(ユーザー「root」@「localhost」へのアクセスが拒否されました(パスワードの使用:NO))。

どうすれば解決できますか?私は数時間この問題で苦労しました。どんな助けでも大変感謝します!

ベストアンサー1

Ubuntuを14.04から16.04にアップグレードするときも同じ問題が発生しました。私はあなたが提案したもの(データベースをエクスポートして再起動する)を実行するのが面倒で、最終的に問題を解決するためにそうしました!

mysqlを停止した後、認証なしで起動

> sudo service stop mysql 
> sudo mkdir /var/run/mysqld # needed to launch mysql in ubuntu from command line...may not apply to other distros
> sudo chown mysql:mysql /var/run/mysqld # same reason as above
> sudo mysqld_safe --skip-grant-tables

次に、別の端末ウィンドウで次の操作を行います。

> mysql -uroot 
> select User, host, authentication_string,plugin from mysql.user; #see what users don't have a password (authentication_string and plugin are empty) 
> update mysql.user set authentication_string=PASSWORD('woot') where user='user';
> update mysql.user set plugin='mysql_native_password' where user='user'; 
> FLUSH PRIVILEGES;
> exit; 

最後に、一時mysql(mysqld_safe)インスタンスを終了し、最初の端末で再起動する必要がありました。

> ^\ #to tell the mysqld_safe process to quit itself 
> sudo service mysqld start 

おすすめ記事