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

Laravel Create database connection in laravel

How to make database connection in Laravel 8 ?

December 14, 2021February 22, 2024

Laravel comes with first party support for several database drivers. Laravel gives much better flexibility in terms of using the RDBMS based databases. Laravel supports MySQL, PostgreSQL, SQLite and SQL Server by default but if you want to make connection with Mongo or other database then you need to install…

Read More

How to start, stop and restart apache linux ?

August 28, 2021August 28, 2021

Before start i hope you know well about the apache, if not then you can read this article what is apache and install on ubuntu. Commands to start, stop, status and restart the apache are as follow: Start Apache in ubuntu command line sudo service apache2 start Restart Apache in…

Read More

How to Import mysql database using command line?

August 24, 2021February 22, 2024

Mysql has rich features for users like they can easily import and export database, create table, relations, store procedures, triggers etc. In the same way mysql has own command to import and export the mysql database. First find the mysql executable.you can open the terminal in ubuntu/Mac or command line…

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

  • 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
  • Understanding High Vulnerabilities: A Deep Dive into the Weekly Summary
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version