How to reset Mysql root password ?
The MySQL root password provides the root user with full access to the MySQL database. If the root password is not remembered or known in the MySQL database, it can be reset as follows.
To reset, a connection must be established with root in Linux environments and with administrator in Windows environments.
The reset steps are as follows.
Shutting down Mysql service:
Ubuntu and Debian;
/etc/init.d/mysql stop
CentOS, Fedora, Red Hat Enterprise Linux or Oracle Enterprise Linux;
/etc/init.d/mysqld stop
Starting Mysql service without password:
mysqld_safe --skip-grant-tables &
mysql -uroot
Setting a new password:
via mysql cli,
use mysql;
update user set password=PASSWORD("newpassword") where User='root';
flush privileges;
quit
Restarting the Mysql service:
/etc/init.d/mysql stop
/etc/init.d/mysql start
Connecting to Mysql database with new password:
mysql -u root -p
When it asks for a password, you can enter the changed password and connect to the mysql command line.
Sample outputs will be as follows.
root@debian:~# /etc/init.d/mysql stop
[ ok ] Stopping mysql (via systemctl): mysql.service.
root@debian:~# mysqld_safe --skip-grant-tables &
[1] 30091
root@debian:~# 180922 22:50:31 mysqld_safe Can't log to error log and syslog at the same time. Remove all --log-error configuration options for --syslog to take effect.
180922 22:50:31 mysqld_safe Logging to '/var/log/mysql/error.log'.
180922 22:50:31 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
root@debian:~# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; o\g.
Your MySQL connection id is 1
Server version: 5.5.55-0+deb8u1 (Debian)
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> 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 password=PASSWORD("newpassword") where User='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 4 Changed: 0 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
root@debian:~# /etc/init.d/mysql stop
[ ok ] Stopping mysql (via systemctl): mysql.service.
root@debian:~# /etc/init.d/mysql start
[ ok ] Starting mysql (via systemctl): mysql.service.
root@debian:~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; o\g.
Your MySQL connection id is 3
Server version: 5.5.55-0+deb8u1 (Debian)
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>









