Skip to content
Readerstacks logo Readerstacks
  • Home
  • Softwares
  • Angular
  • Php
  • Laravel
  • Flutter
Readerstacks logo
Readerstacks
How to Reset Root Password of MySQL 8 in Ubuntu 20.04

How to Reset Root Password of MySQL 8 in Ubuntu 20.04 ?

Aman Jain, June 1, 2022June 1, 2022

Sometimes we forget or mistakenly type wrong password during the installation of mysql, So in this article i will help you to Reset Root Password of MySQL in Ubuntu 20.04. Mysql 8 has several new features and also it has change the default password algorithm for saving the password. Mysql 8 now using the caching_sha2_password algorithm to save the password in the database.

In the recent version of mysql we can easily change the password using the PASSWORD function of mysql but now PASSWORD function is deprecated in mysql 8 so we need a different technique to reset the password.

So today i come with a simple solution to reset the root password of mysql 8 in Ubuntu. Let’s start with step by step

Step 1 : Login in to the ubuntu server

As we all know first we need to login into the server or machine to access the mysql so ssh using below command

ssh username@domain_ip

Enter your password and you are into the server.

Step 2 : Update configuration of mysql

Next, we need to open my.cnf configuration file of mysql which is most probably located in /etc/mysql/my.cnf so open the file using vim or any your favorite editor

sudo vim /etc/mysql/my.cnf

Add below skip-grant-tables in [mysqld] block as below

[mysqld]

skip-grant-tables

Step 3 : Restart MySQL

We have changed the configuration files so we need to reload the mysql service

systemctl restart mysql

Check status again

systemctl status mysql

Step 4 : Login into Mysql and Change Password

Now, we can login without password as we have enabled the safe mode using skip-grant-tables

mysql -u root

Now update password to null

UPDATE mysql.user SET authentication_string=null WHERE User='root';
FLUSH PRIVILEGES;
exit;

And again remove the skip-grant-tables from my.cnf file

[mysqld]

#skip-grant-tables

Step 5 : Restart and Login again without password

systemctl restart mysql

Next, we can login without password

mysql -u root -p

Step 6 : Update Root Password

Final step is to update the password of root so replace yourpasswd with your password

ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'yourpasswd';

Related

Ubuntu Devops Mysql mysqlpasswordroot

Post navigation

Previous post
Next post

Related Posts

Php connect php to mysql

How to connect PHP to MySQL ?

September 27, 2021September 29, 2021

PHP is commonly used in the world of web. PHP has many built in tools to connect with different drivers and in this tutorial we are going to use MySQL driver to connection between PHP and MySQL. There is two to connect database in PHP 5 and later version. MySQLi…

Read More

What is apache web server and install on ubuntu?

August 28, 2021August 29, 2021

Apache is a web server which is used to serve the http request from a client computer. A client can open a webpage to view the website using web browsers like chrome, firefox etc. and browsers sent their requests to web servers like apache http server. How to install Apache…

Read More
Softwares ssh disable

Disable SSH or IP bounded on any ubuntu server?

July 11, 2021February 22, 2024

Open SSH to everyone is a security risk. we can change these settings easily in 2 minutes. let’s have quick solution on this. Open file /etc/hosts.deny with using vi or nano editor. Command : sudo vi /etc/hosts.deny then add below line to the file. sshd,sshdfwd-X11 : ALL it will look…

Read More

Aman Jain
Aman Jain

With years of hands-on experience in the realm of web and mobile development, they have honed their skills in various technologies, including Laravel, PHP CodeIgniter, mobile app development, web app development, Flutter, React, JavaScript, Angular, Devops and so much more. Their proficiency extends to building robust REST APIs, AWS Code scaling, and optimization, ensuring that your applications run seamlessly on the cloud.

Categories

  • Angular
  • CSS
  • Dart
  • Devops
  • Flutter
  • HTML
  • Javascript
  • jQuery
  • Laravel
  • Laravel 10
  • Laravel 11
  • Laravel 9
  • Mysql
  • Php
  • Softwares
  • Ubuntu
  • Uncategorized

Archives

  • July 2025
  • June 2025
  • May 2025
  • April 2025
  • October 2024
  • July 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • July 2023
  • March 2023
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Recent Posts

  • Mastering Schedule Management with Laravel Zap
  • The Resilience of Nature: How Forests Recover After Fires
  • Understanding Laravel Cookie Consent for GDPR Compliance
  • Understanding High Vulnerabilities: A Critical Overview of the Week of May 12, 2025
  • Installing a LAMP Stack on Ubuntu: A Comprehensive Guide
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version