By using this site, you agree to the Privacy Policy.
Accept
EnterinITEnterinITEnterinIT
  • HOME
  • IT PRO
  • TECH
  • MICROSOFT
    • Azure
    • ConfigMgr/SCCM
    • DPM
    • Orchestrator
    • Hyper-V
    • Microsoft Edge Insider
    • MSI
    • Office 365
    • Office Insider
    • Power BI
    • Skype
    • SQL Server
    • Teams
  • WINDOWS
    • Windows Admin Center
    • Windows Client
    • Windows Server
  • SCCM Query Collection List
Reading: Reset MySQL Root Password on Linux: A Step-by-Step Guide
Font ResizerAa
EnterinITEnterinIT
Font ResizerAa
  • HOME
  • IT PRO
  • TECH
  • MICROSOFT
  • WINDOWS
  • SCCM Query Collection List
Search
  • HOME
  • IT PRO
  • TECH
  • MICROSOFT
    • Azure
    • ConfigMgr/SCCM
    • DPM
    • Orchestrator
    • Hyper-V
    • Microsoft Edge Insider
    • MSI
    • Office 365
    • Office Insider
    • Power BI
    • Skype
    • SQL Server
    • Teams
  • WINDOWS
    • Windows Admin Center
    • Windows Client
    • Windows Server
  • SCCM Query Collection List
MySQL

Reset MySQL Root Password on Linux: A Step-by-Step Guide

Published: February 18, 2024
3 Min Read
SHARE

Reset MySQL Root Password on Linux: A Step-by-Step Guide.

Losing or forgetting the MySQL root password can be a daunting situation for database administrators. However, on a Linux system, there are methods to reset the MySQL root password and regain access to your database. In this article, we will guide you through the process of resetting the MySQL root password on Linux by modifying the MySQL configuration file (my.cnf), ensuring the security and integrity of your valuable data.

1. The first step in resetting the MySQL root password is to stop the MySQL service to prevent any active connections. Open a terminal on your Linux system and execute the following command:

sudo systemctl stop mysql

2. Next, you need to modify the MySQL configuration file (my.cnf) to disable the authentication process temporarily. Open the file using a text editor:

sudo nano /etc/mysql/my.cnf

Locate the [mysqld] section in the file and add the following line below it:

skip-grant-tables

NOTE: In case, when [mysqld] not exist use this code:

[mysqld]
skip-grant-tables

Save the changes and exit the text editor.

3. After modifying the configuration file, you need to restart the MySQL service for the changes to take effect. Execute the following command in the terminal:

sudo systemctl restart mysql

NOTE: The MySQL service will now start without checking the user privileges, allowing you to reset the root password without providing the current password.

4. Now that MySQL is running with the authentication process disabled, open a terminal and connect to the MySQL server using the following command:

mysql -u root

Once connected to the MySQL server, execute the following SQL statement to flush privileges:

FLUSH PRIVILEGES;

NOTE: Without it, you will get errors on any user operations.

Once connected to the MySQL server, execute the following SQL statement to update the root password:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

Replace ‘new_password’ with your desired password. After running the query, you can exit the MySQL prompt by typing exit or quit.

FLUSH PRIVILEGES;
exit;

NOTE: Don’t forget to comment code on my.cnf

#[mysqld]
#skip-grant-tables
TAGGED:AlmaLinuxCentOSdbLinuxMySQLUbuntu
Previous Article How to Update Sysmon on Windows – Step by Step Guide
Next Article Office Insider 2212 for Windows
Leave a Comment Leave a Comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Translation

English中文(简体)DanskNederlandsFrançaisDeutschItaliano한국어PolskiPortuguêsRomânăEspañolУкраїнська
by Transposh - translation plugin for wordpress

Popular Posts

System Requirements for Windows Server 2016
Windows Server
Configuration Manager Query Collection List
Configuration Manager Query Collection List
ConfigMgr
Structured/Managed Navigation enabled on Modern Pages in Classic Team Sites
Tech
SCCM Failed to get DP locations as the expected version from MP
ConfigMgr

Recent Posts

Installing and Configuring Fail2ban for SSH Protection on Ubuntu 24.04
Linux
Enabling and Configuring FirewallD on AlmaLinux
Linux
User Creation and SSH Key Setup in AlmaLinux
Linux
How to reset password on AlmaLinux
Linux

© 2023 EnterinIT

Go to mobile version
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?