Reset MySQL Root Password on AlmaLinux / Rocky Linux

In this guide, you will learn to Reset or Change your Forgotten MySQL Root Password on AlmaLinux / Rocky Linux.

The MySQL root password is the password set for the root user account in MySQL, which has administrative privileges and full access to all databases and operations within MySQL. When MySQL is initially installed, you may be prompted to set a password for the root user, or it may be left blank initially.

If you have forgotten or need to reset the MySQL root password, you can follow the steps below.

Steps To Reset MySQL Root Password on AlmaLinux / Rocky Linux

You can use this instruction for 8 and 9 versions of AlmaLinux and Rocky Linux. To complete this guide, log in to your server as a non-root user and follow the steps below. To get the initial server setup guides, you can visit the Orcacore website.

Here to show you the guide steps we use AlmaLinux 9. Now follow the steps below to complete this guide.

Step 1 – Stop MySQL Service on AlmaLinux / Rocky Linux

First, you can verify your MySQL version installed on your server:

mysql --version
Example Output
mysql  Ver 8.0.36 for Linux on x86_64 (MySQL Community Server - GPL)

Then, you must stop your MySQL service with the following command:

sudo systemctl stop mysqld 

When the MySQL service is stopped, you can restart it safely to reset the root password.

Step 2 – Access MySQL without a Password

At this point, you must use the Skip-Grant-Tables option which disables the authentication and authorization checks. This will allow you to connect to your MySQL service without a password. To do this, you can run the command below:

sudo systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"

Then, start your MySQL service on AlmaLinux / Rocky Linux:

sudo systemctl start mysqld

Now you can connect to your MySQL as a root user:

mysql -u root
Access MySQL without a Password

Step 3 – Set a New MySQL Root Password

From your MySQL shell, you can use the following commands to reset your root password:

 USE mysql;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Strong#Password';
mysql> QUIT;

Note: If you are getting an error during the changing password like this:

The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

You can fix it by running the FlUSH PRIVILEGES; command and then again changing your password.

The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

Once you are done, stop your MySQL service and unset the grant tables option:

# sudo systemctl stop mysqld
# sud systemctl unset-environment MYSQLD_OPTS

Next, start your MySQL service and try to log in to the shell with your password:

# sudo systemctl start mysqld
# sudo mysql -u root -p


It’s important to keep the MySQL root password secure and to only share it with authorized users who require administrative access to the MySQL server. Additionally, it’s recommended to periodically change the root password for security purposes.

Hope you enjoy this guide on Reset MySQL Root Password on AlmaLinux / Rocky Linux. Also, you may like to read the following articles:

Change Root Password on Rocky Linux 9

Change Root Password on AlmaLinux 9

Reset MySQL And MariaDB Root Password on Ubuntu 22.04

Reset Linux Root Password on Debian 12 Bookworm

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!