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 a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button