CentOSLinuxUbuntu

How To Reset Root Password MySQL Server

Reset Root Password MySQL Server

In this tutorial, we will show you how to reset the root password MySQL server. Have you ever forgotten the root password for your MySQL server and been locked out of your own database? It can be a frustrating experience but don’t worry, you’re not alone. In this blog post, we will guide you through the process of resetting the root password on your MySQL server. We will cover various methods for resetting the root password, including using the command line and modifying configuration files. So whether you’re a MySQL novice or an experienced administrator, this guide will help you regain access to your server and ensure your database stays secure.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step reset root password MySQL server.

Prerequisites

  • A server running one of the following operating systems: Debian-based or RHEL-based.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Reset Root Password MySQL Server

Step 1. Stop the MySQL Service.

The first step in resetting the root password for MySQL is to stop the MySQL service. You can do this by running the following command:

sudo systemctl stop mysql

Step 2. Start the MySQL Service in Safe Mode.

After stopping the MySQL service, you can start it in safe mode. Safe mode ensures that MySQL does not load the grant tables, which store user account information. This step is important because it allows you to reset the root password without having to provide it. To start the MySQL service in safe mode, use the following command:

sudo mysqld_safe --skip-grant-tables &

Step 3. Reset Root Password MySQL Server.

After starting MySQL in safe mode, you can reset the root password. Follow the steps below to reset the password:

mysql -u root

Switch to the MySQL database:

use mysql;

Next, update the root password using the following command:

update user set authentication_string=PASSWORD('newpassword') where User='root';

*Replace newpassword with your desired new password.

Then, flush the privileges and exit the MySQL shell:

flush privileges;
exit;

Finally, restart the MySQL service by running the following command:

sudo systemctl start mysql

For additional resources on installing MySQL, read the post below:

Congratulations! You have successfully reset your password MySQL. Thanks for using this tutorial to reset the root password MySQL on the Linux system. For additional help or useful information, we recommend you check the official MySQL website.

MySQL Fix Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “MySQL Fix”, starting from $10 (Paypal payment). Please contact us to get the best deal!

Save

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button