AtulHost
  • Business
    • Career and Education
    • Finance and Investments
    • Marketing Strategies
  • Productivity
  • Technology
    • Consumer Electronics
    • Solar Energy
  • Tutorials

How to reset MySQL root password?

By AtulHost in Tutorials ⋅ May 27th, 2015
Facebook Tweet LinkedIn

If you are using Linux and ever lose your MySQL root password or never set a root password and now unable to access it, so don’t worry, there is an easy way to reset MySQL root password. On all the modern Linux distribution you can recover the MySQL root password in just a few easy steps.

How to Reset MySQL Root Password

1. Stop all the MySQL Processes

On Ubuntu and Debian distributions.

service mysql stop

On CentOS, Fedora and RHEL distributions.

service mysqld stop

2. Start MySQL Server with Safe Mode

mysqld_safe --skip-grant-tables &

3. Connect to the MySQL Server

mysql -u root

4. Setup a New MySQL Root Password

use mysql;
update user set password=PASSWORD("YourNewPassword") where User='root';
flush privileges;
exit

5. Stop MySQL Server and Start MySQL

On Ubuntu and Debian distributions.

service mysql stop
service mysql start

On CentOS, Fedora and RHEL distributions.

service mysqld stop
service mysqld start

Now you can test your new MySQL root password via logging in to it normally.

mysql -u root -p

After entering the above command, you will be prompted for new MySQL root password. You can verify it whether it is working or not in the shell.

This way you can reset the MySQL root password and make it accessible again.

Tagged with MySQL, password, security.
Facebook Tweet LinkedIn

Published by AtulHost

Atul is a creative blogger who loves to do experiments with the latest business initiatives and tech trends like automation, artificial intelligence, cloud and edge computing, data science, hardware as well as networking, and the internet of things.

Users also read these

  • How to handle business from all the odds?
  • Build a Better Business: The Office Edition
  • 5 tips to ensure data safety in 2021
  • How to make sure a website is safe (and your data is too)
  • Online Banking Security Measures to Keep Fraudsters Away

Comments and feedback

  1. Pedro says:
    January 19th, 2017 at 4:22 AM

    Hi Atul, I have a problem because mine setup says “Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock'”.

    Reply to
    • AtulHost says:
      January 21st, 2017 at 9:28 AM

      This error occurs due to multiple installations of mysql.

      Try a service restart or server reboot once. If you are still facing this issue even after restarting mysql services then run the following commands:

      ps -A|grep mysql

      Kill the process by using:

      sudo pkill mysql

      and then run command:

      ps -A|grep mysqld

      Also Kill this process by running:

      sudo pkill mysqld

      Now you are fully set just run the following commands:

      service mysql restart
      mysql -u root -p

      Now have very well working mysql again. Have a backup of your all database because nothing is more important than your precious data.

      Reply to
  2. Melker says:
    January 26th, 2018 at 10:29 PM

    Hi! Very good help, the only problem I have is that I don’t get MySQL to start. This is the error I get: Job for mariadb.service failed because a timeout was exceeded.

    See “systemctl status mariadb.service” and “journalctl -xe” for details. (And on top of that, my MySQL is named MariaDB for some reason?)

    Reply to
    • AtulHost says:
      January 27th, 2018 at 11:04 PM

      Hi Melker, first of all, do not get confused with MySQL named as MariaDB it is a child of the same branch that follows the new rule (maybe you have installed or upgraded to MariaDB from MySQL).

      About the error, it seems to be an error with either permission or any app is creating a problem for MySQL to start. I will suggest to read the error log and find the culprit where it log will show something like “DENIED”. Then try to troubleshoot that error.

      TIP: If the error is about APPARMOR then quick fix is ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/ and reboot.

      Reply to

Make a comment Cancel reply

Required fields are asterisked and your email address will not be shared.

Subscribe
10x your productivity
Increase your conversion rates

We use cookies to serve the best experience on our site. Got it!

  • About
  • Contact
  • Privacy Policy
  • Terms and Conditions
  • Write for Us
This website and its content are copyrighted © 2014-2021 by atulhost.com and individual contributors.