mysqlのpasswordを忘れた時

passwordが違うと表示
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)

さっぱり覚えていない
ec2の初期パスワードか?
[ec2-user@ ~]$ cat /var/log/mysqld.log

[ec2-user@ ~]$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)
違うらしい。。

mysqlを止めて、/etc/my.cnfを編集
[ec2-user@ ~]$ sudo service mysqld stop
Stopping mysqld: [ OK ]
[ec2-user@]$ sudo vi /etc/my.cnf

skip-grant-tables を追加

再起動して、-pなしでログイン
[ec2-user@~]$ sudo service mysqld start
Starting mysqld: [ OK ]
[ec2-user@ ~]$ mysql -u root

> UPDATE mysql.user SET authentication_string = PASSWORD(‘new password’) WHERE User = ‘root’ AND Host = ‘localhost’;
> FLUSH PRIVILEGES;

[ec2-user@]$ sudo vi /etc/my.cnf
# skip-grant-tables //コメントアウト

$ sudo service mysqld restart
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]
[ec2-user@ ~]$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

OK!ふう、焦った~