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
答え2
問題は、debian-sys-maint を含むすべてのユーザーの mysql.user プラグイン値が空だったため、パッケージを再構成することすらできなかったことです。mysql_upgrade を実行することで修正されるはずでしたが、何らかの理由で修正されませんでした。
そこで、すべてのデータベースのダンプを作成し、MySQL サーバーを完全に削除してから再インストールし、データベースを再度インポートしました。
すべてのデータベースをダンプします:
> mysqldump -u root -p --databases db1 db2 > alldb.sql
かなり愚かなことですが、--all-databases を使用してすべてのデータベースのダンプを実行しました。これには、すべてのユーザーの「プラグイン」値が空の mysql.user テーブルが含まれていたため、mysql サービスの最初の再起動後に同じ問題が発生しました。そのため、その後は自分のデータベースのみのダンプを実行しました。
ダンプはコマンドを実行したフォルダに保存されます。
MySQLとその設定を削除します。
> sudo apt-get purge mysql-server mysql-client mysql-common mysql-server-core-5.7 mysql-client-core-5.7
> sudo rm -rf /etc/mysql /var/lib/mysql
> sudo apt-get autoremove
> sudo apt-get autoclean
MySQLをインストールします。
> sudo apt-get install mysql-server
データベースを再度インポートします。
> mysql -u root -p < alldb.sql