habibzain Just husband, father and enthusiastic men about System Administration. Love to write short article about it. Perhaps can help and be useful for others.

MySQL Reset Root Password

1 min read

Hi People. Everyone ever make a wrong decision, that can make a trouble. At this time i get error about mysql. Human error that force mysql server to reset root password.

root@ip-10-179-164-79 ~# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)  

Solution:

  1. Stop service mysql. And run mysql in safe mode
root@ip-10-179-164-79 ~# /etc/init.d/mysqld stop
root@ip-10-179-164-79 ~# mysqld_safe –skip-grant-tables & mysql -u root
mysql> use mysql;

mysql> update user set password=PASSWORD(“newrootpassword”) where User=’root’;

mysql> flush privileges;

mysql> quit
  1. Restart service mysql.
root@ip-10-179-164-79 ~# /etc/init.d/mysqld stop
root@ip-10-179-164-79 ~# /etc/init.d/mysqld start 

Once after setting the password even again I have encountered the below error and then set the password , try login again from the operating system level.

mysql> show databases;
 ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
 
 mysql> use mysql;
 ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
 
 mysql> update user set password=PASSWORD(“root1234”) where User=’root’;
 ERROR 1820 (HY000): You must SET PASSWORD before executing this statement

Even finished update user root password, still can not login mysql. Finally use global config SET PASSWORD.

root@ip-10-179-164-79 ~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.6.16
Copyright (c) 2000, 2014, 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> SET PASSWORD = PASSWORD(‘root1234’);

Try to login mysql root again.

root@ip-10-179-164-79 ~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.6.16 MySQL Community Server (GPL)
Copyright (c) 2000, 2014, 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> show databases;
 +——————–+
 | Database |
 +——————–+
 | information_schema |
 | mysql |
 | performance_schema |
 | test |
 +——————–+
 4 rows in set (0.00 sec)
 Query OK, 0 rows affected (0.00 sec)

That is my note about mysql reset root password. May be it’s helpful, please feel free to leave a comment if you have any questions and I’ll appreciate it.


habibzain Just husband, father and enthusiastic men about System Administration. Love to write short article about it. Perhaps can help and be useful for others.

Fix mysqli_real_connect Access denied for user ‘root’@’localhost’

Have we ever face the error mysqli_real_connect(): (HY000/1698): Access denied for user ‘root’@’localhost’ when logging in as root on the mysql server? In this...
habibzain
2 min read

ISPConfig Ubuntu 18.04 Nginx MySQL

In this blog post, I will show you how to install and configure ISPConfig Ubuntu 18 with Nginx web server. ISPConfig is a powerful...
habibzain
5 min read

Install Percona Server for MySQL 5.6 In Ubuntu 18

Hi Dude. In this article, I will show you how to install Percona MySQL 5.6 on Ubuntu 18.04 LTS. Percona MySQL is a drop-in...
habibzain
1 min read

Leave a Reply

Your email address will not be published. Required fields are marked *

Never miss good article from us, get weekly updates in your inbox