MySQL8.0でのrootパスワードリセット

MySQL8.0でのrootパスワードリセット

MySQL8.0にしたのはいいんだけど、しばらくつかってないもんだからrootのパスワードがわからなくなってしまいました。
MySQL8.0からパスワードリセットの方法が変わったようなのでメモ書き。

/etc/my.cnfで権限スキップの設定を入れて再起動

[mysqld]
skip-grant-tables 
# systemctl restart mysqld

mysqlにrootで入って、rootのパスワードをnullに設定する。

# mysql -u root
mysql > update mysql.user set authentication_string=null where user='root';

権限スキップの設定を外してmysqldを再起動

[mysqld]
#skip-grant-tables 
# systemctl restart mysqld

alterでrootのパスワードを変更

# mysql -u root
mysql> alter mysql.user 'root'@'localhost' identified by 'hogehoge' ;

Query OK, 1 row affected (0.04 sec)
Rows matched: 1  Changed: 1  Warnings: 0

これ、権限スキップ状態だとこんなエラーがでます。

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement