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

Devops How to add ssh keys to git or bit bucket

How to add ssh keys to git or bit bucket ?

July 3, 2024July 3, 2024

If you’re a developer working with Bit bucket repositories, using SSH keys can make your workflow more secure and efficient. Instead of entering your username and password each time you interact with your repository, SSH keys provide a seamless and secure connection. In this guide, we’ll walk you through the…

Read More
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
Devops Install php, apache, mysql(Lamp) and phpmysadmin on Ubuntu

How to Install php apache mysql(Lamp) and phpmysadmin on Ubuntu

September 18, 2021November 8, 2023

In this article we will learn to Install php apache mysql(Lamp) and phpmysadmin on Ubuntu. PHP, Apache MySQL and phpMyAdmin is most useful part to run a web application like PHP. In this tutorial we will cover installation of PHP 7, Apache, MySQL and phpMyAdmin. Here is the list of…

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

  • August 2025
  • 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

  • The Transformative Power of Education in the Digital Age
  • Understanding High Vulnerabilities: A Closer Look at the Week of July 14, 2025
  • Exploring Fresh Resources for Web Designers and Developers
  • The Intersection of Security and Technology: Understanding Vulnerabilities
  • Mapping Together: The Vibrant Spirit of OpenStreetMap Japan
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version