Step # 1: Stop the MySQL server process.
[root@testdb1 ~]# /etc/init.d/mysqld stop
Stopping mysqld: [ OK ]
Step # 2: Start the MySQL (mysqld) server/daemon process with the --skip-grant-tables option so that it will not prompt for a password.
[root@testdb1 ~]# mysqld_safe --skip-grant-tables &
[1] 12703
[root@testdb1 ~]# 2017-07-16T19:08:25.101474Z mysqld_safe Logging to '/var/log/mysqld.log'.
2017-07-16T19:08:25.114178Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Step # 3: Connect to the MySQL server as the root user.
[root@testdb1 ~]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.18 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
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>
Step # 4: Set a new root password and exit
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set authentication_string=PASSWORD("New_Password");
Query OK, 2 rows affected, 1 warning (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
Step # 5: Restart the MySQL server and Test
[root@testdb1 ~]# /etc/init.d/mysqld stop
2017-07-16T19:28:04.053532Z mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Stopping mysqld: [ OK ]
[1]+ Done mysqld_safe --skip-grant-tables
[root@testdb1 ~]# /etc/init.d/mysqld start
Starting mysqld: [ OK ]
[root@testdb1 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.18 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
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>