Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 8314

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 60k
Author
Asked: November 28, 20242024-11-28T11:58:07+00:00 2024-11-28T11:58:07+00:00

How to Reset MySQL root password in Ubuntu

  • 60k

Passwords are hard to remember, so if you have forgotten the MySQL root password, luckily, there is a way to change it. This post has been written for you, and by the end of this post, you will have successfully changed the password of MySQL.

This blog demonstrates how to reset the root password for MySQL and MariaDB databases installed with the apt package manager on Ubuntu. The procedure for changing the root password differs depending on whether you have MySQL installed and the default systemd configuration that ships with the distribution or packages from other vendors.

Before moving on to the answer, it is assumed that you have the latest version of the MySQL database for Ubuntu. This blog will offer an easy-to-follow guide for changing your MySQL root passwords in Ubuntu. Therefore, without wasting time, let's begin.

1. Check MySQL Version

First, check the version of your MySQL because this post contains the solution of changing the root password on version 8 or higher. If the version of your MySQL is lower than 8, then the answer will be different. Run the following command:

mysql --version 
Enter fullscreen mode Exit fullscreen mode

MySQL Version Output:

mysql  Ver 8.0.27-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu)) 
Enter fullscreen mode Exit fullscreen mode

2. Stop MySQL Server

To change the MySQL root password, you first need to shut down the MySQL server, run the following command:

sudo systemctl stop mysql.service 
Enter fullscreen mode Exit fullscreen mode

Check the status of the MySQL server to verify. Run the following command:

sudo systemctl status mysql.service 
Enter fullscreen mode Exit fullscreen mode

3. Skip Grant Tables & Networking

To start the MySQL server without granting the tables and networking check, set the environment variable MYSQLD_OPTS, which MySQL uses on startup. Run the following command:

sudo systemctl set-environment MYSQLD_OPTS="--skip-networking --skip-grant-tables" 
Enter fullscreen mode Exit fullscreen mode

Alright, the environment variable is a set, and we can log in to the MySQL shell providing no password.

4. Start MySQL Service

After setting the environment variable MYSQLD_OPTS, start the MySQL service. Run the following command:

sudo systemctl start mysql.service 
Enter fullscreen mode Exit fullscreen mode

5. Login To MySQL Shell

At this stage, we can access the MySQL database without a password:

sudo mysql -u root 
Enter fullscreen mode Exit fullscreen mode

6. Reset Root Password

Now, flush the privileges first. Run the following command:

sudo mysql -u root flush privileges; 
Enter fullscreen mode Exit fullscreen mode

Select the MySQL database. Run the following command:

use mysql; 
Enter fullscreen mode Exit fullscreen mode

How to Reset MySQL root password in Ubuntu
And set the new password for the root user, run the following command:

ALTER USER  'root'@'localhost' IDENTIFIED BY '(YOUR NEW PASSWORD)'; 
Enter fullscreen mode Exit fullscreen mode

How to Reset MySQL root password in Ubuntu
At the place of (YOUR NEW PASSWORD) provide your new password. After successfully changing the MySQL root password, log out from the MySQL shell.

quit; 
Enter fullscreen mode Exit fullscreen mode

How to Reset MySQL root password in Ubuntu

7. Kill All MySQL Processes and Restart MySQL Service

First, kill all the processes of MySQL before even restarting the MySQL server.

sudo killall -u mysql 
Enter fullscreen mode Exit fullscreen mode

And the restart the MySQL server, run the following command:

sudo systemctl restart mysql.service 
Enter fullscreen mode Exit fullscreen mode

8. Login MySQL With New Password

If all goes well, you should now be able to login to your MySQL database with a root password:

sudo mysql -u root -p 
Enter fullscreen mode Exit fullscreen mode

How to Reset MySQL root password in Ubuntu
Thank you for reading this blog.

linuxmysqlubuntuwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 1k
  • Popular
  • Answers
  • Author

    How to ensure that all the routes on my Symfony ...

    • 0 Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.