Learning and Sharing
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
No Result
View All Result

How to Reset the MySQL Root Password on Linux

November 3, 2022
in Blog, Linux
0
ADVERTISEMENT

Table of Contents

In some cases, you’ve forgotten the MySQL root password, or it has mysteriously changed. In this post, we will reset the MySQL root password in Linux by starting MySQL with the –skip-grant-tables option.

Note Note: Running MySQL with the —skip-grant-tables option enabled is highly insecure and should only be done for a brief period while you reset the password. The steps below show you how to stop the mysqld_safe server instance safely and start the MySQL server securely after you have reset the root password.

Preparing

1. Firstly, you must confirm which version of MySQL on Linux you are running as commands will be different. In our case, the version of MySQL is 10.8.5.

# mysql -V
mysql  Ver 15.1 Distrib 10.8.5-MariaDB, for Linux (x86_64) using readline 5.1

2. In order to skip the grant tables and reset the root password, we must first stop the MySQL service. Stop the MySQL server using the appropriate command for your Linux distribution:

###For CentOS and Fedora
sudo service mysqld stop

###For Debian and Ubuntu
sudo service mysql stop

3. Restart the MySQL server with the —skip-grant-tables option. To do this, type the following command:

mysqld_safe --skip-grant-tables &
Note Note: Make sure you type the ampersand (&) at the end of the command. This runs the command in the background and allows you to type the commands in the following steps.
# sudo mysqld_safe --skip-grant-tables
221103 09:11:29 mysqld_safe Logging to '/var/lib/mysql/ct7.err'.
221103 09:11:29 mysqld_safe Starting mariadbd daemon with databases from /var/lib/mysql

5. Now press to return to the Linux Bash prompt. Then run the following command to login into MySQL without any password.

sudo mysql --user=root mysql
# sudo mysqld_safe --skip-grant-tables
221103 09:11:29 mysqld_safe Logging to '/var/lib/mysql/ct7.err'.
221103 09:11:29 mysqld_safe Starting mariadbd daemon with databases from /var/lib/mysql

# sudo mysql --user=root mysql

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.8.5-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [mysql]>

Reset MySQL root password in Linux

Reset root password for MySQL 8+

1. At the prompt, let’s reset the root account password. To do this, type the following command, replacing new_password with the new root password:

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

2. Flush the privileges then exit.

flush privileges;
exit;

3. Stop the MySQL server using the following command. You will be prompted to enter the new MySQL root password before the MySQL server shuts down:

mysqladmin -u root -p shutdown
# mysqladmin -u root -p shutdown
Enter password:
[1]+  Done                    mysqld_safe --skip-grant-tables

4. Start the MySQL service on your Linux server using the following command:

###For CentOS and Fedora
sudo service mysqld start

###For Debian and Ubuntu
sudo service mysql start

5. Finally, log in to MySQL again and you should now be prompted for a password. Enter your new MySQL root password to verify it’s working.

# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.8.5-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

Reset root password for MySQL 5.7

For MySQL 5.7 on Linux, run below command to change the root password. Don’t forget replacing new_password with your own.

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

Flush the privileges and exit. Don’t forget shutdown then restart the MySQL service.

flush privileges;
exit;

Reset root password for MySQL 5.6

For MySQL 5.6 on Linux, run below command to change the root password. Don’t forget replace new_password with your own.

update user set Password=PASSWORD('new_password') where user='root';
ADVERTISEMENT
5/5 - (1 vote)
Previous Post

How to Fix phpMyAdmin Access Denied for User Root Localhost

Next Post

ERROR 1290 (HY000) The MariaDB Server Cannot Execute This Statement

Related Posts

Running Hyper-V and VMware Workstation on The Same Machine

August 15, 2024

How to Uninstall All Autodesk Products At Once Silently

July 29, 2024
Ftr5

How to Uninstall the Autodesk Genuine Service on Windows

July 29, 2024
Ftr19

How to Fix Windows Cannot Read the ProductKey From the Unattend Answer File in VirtualBox

July 26, 2024
Ftr25

How to Update Windows Terminal in Windows 10/11

July 26, 2024

How to Disable The Beep Sound in WSL Terminal on Windows

July 26, 2024

Leave a Reply Cancel reply

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

Recent Posts

  • How To Turn On uBlock Origin Extension in Chrome (2025)
  • Images Hidden Due To Mature Content Settings In CivitAI
  • Azure OpenAI vs Azure AI Hub, How to Choose the Right One for Your Needs

Categories

Stay in Touch

Discord Server

Join the Discord server with the site members for all questions and discussions.

Telegram Community

Jump in Telegram server. Ask questions and discuss everything with the site members.

Youtube Channel

Watch more videos, learning and sharing with Leo ❤❤❤. Sharing to be better.

Newsletter

Join the movement and receive our weekly Tech related newsletter. It’s Free.

General

Microsoft Windows

Microsoft Office

VMware

VirtualBox

Technology

PowerShell

Microsoft 365

Microsoft Teams

Email Servers

Copyright 2025 © All rights Reserved. Design by Leo with ❤

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory