Database

How To Recover MySQL Root Password

In this article I will explain how to recover MySQL root password. If you have forgotten the MySQL root password you will get this error “ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)” . You can recover MySQL database root password using the following five easy steps:

Steps:

1. Stop MySQL service/process.
2. Start MySQL server in safe mode with –-skip-grant-tables options so that it will not ask for a password.
3. Connect MySQL server as the root user.
4. Update/Set a new root password.
5. Restart MySQL server.

Follow the below command to do the above steps.

Step #1: Stop MySQL Service/Process

# /etc/init.d/mysqld stop

Sample output:

Stopping MySQL database server: mysqld.

Step #2: Start MySQL Server In Safe Mode With –skip-grant-tables

# mysqld_safe --skip-grant-tables &

Sample output:

[1] 4977
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6025]: started

Step #3: Connect MySQL Server Using MySQL Client

# mysql -u root

Sample output:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 228142449
Server version: 5.1.73-log Source distribution

Copyright (c) 2000, 2013, 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: Update/Set New MySQL Root User Password

mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit

Step #5: Restart MySQL Server

# /etc/init.d/mysqld stop
# /etc/init.d/mysqld start

Now connect MySQL server with new root password.

# mysql -u root -p

That’s it.

Thanks:)

Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment