If you are forgot the MySQL server root password easily update it. This post sections provide password-resetting steps on Linux system.

MySQL provide an option "--skip-grant-tables" restart or update new password, This option is insecure. Using this anyone able to connect without password and with all privileges and disables ALTER user and SET PASSWORD.

Note : 

MySQL 5.7.6 and later Version:

mysql >  ALTER USER 'root'@'localhost' IDENTIFIED BY 'root-password';


MySQL 5.7.5 and earlier Version:

mysql >  SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root-password');


Stop the MySQL server if necessary,
 
# /etc/init.d/mysqld stop
Stopping mysqld:             [  OK  ]


mysqld_safe command to start mysql server with --skip-grant-tables,
 
# mysqld_safe --skip-grant-tables &

[1] 6010
 150529 18:06:39 mysqld_safe Logging to '/var/log/mysqld.log'.
150529 18:06:39 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql


Enter into MySQL Server,
 
​# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.7-rc MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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.


Now, reset password,


mysql >  FLUSH PRIVILEGES;

mysql >  ALTER USER 'root'@'localhost' IDENTIFIED BY 'root-password';

mysql >  exit


Finally, stop and start the MySQL server again,
 
# /etc/init.d/mysqld stop

150529 18:08:05 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Stopping mysqld:                                           [  OK  ]
[1]+  Done                    mysqld_safe --skip-grant-tables

 
# /etc/init.d/mysqld start

Now, try to login with new password,
 
# mysql -u root -p
Enter password: 


mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)