How to reset root’s MySQL password?

[root@server /]# service mysqld stop
or
[root@server /]# systemctl start mysqld

[root@server /]# /usr/bin/safe_mysqld --skip-grant-tables &
or
[root@server /]# mysqld --skip-grant-tables --user=mysql

[root@server /]# mysql mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 3.23.58

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> UPDATE user SET Password=PASSWORD('your_new_root_password')
-> WHERE Host='localhost' AND User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> exit;
Bye


or

[root@server /]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.31 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> FLUSH PRIVILEGES;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_new_root_password';
Query OK, 0 rows affected (0.00 sec)

mysql> quit;
Bye

[root@server /]# ps aux|grep mysqld
mysql     5370  1.0  2.2 2258596 374492 pts/0  Sl+  14:25   0:00 mysqld --skip-grant-tables --user=mysql
root      5427  0.0  0.0 112812   980 pts/1    S+   14:26   0:00 grep --color=auto mysqld
[root@server /]# kill -9 5370


[root@server /]# service mysqld restart
or
[root@server /]# systemctl start mysqld


[root@server /]# rm -rf ~/.mysql_history