CentOS 7 Reset Your MySQL or MariaDB Root Password
Today I am going to share how to reset root password of MySQL/MariaDB.
Table of Contents
Step 1 : Stop Database Server
If you don’t know the database server (MySQL or MariaDB) of your server then you can see by typing this command:
To reset the root password, we need to stop the database server. Let’s do this by hitting this command:
# MySQL sudo systemctl stop mysql #MariaDB sudo systemctl stop mariadb
Step 2 : Change the Root Password
Start the database server without loading the grant tables:
sudo mysqld_safe --skip-grant-tables --skip-networking &
Now login to MySQL server as root. It should not ask for password.
mysql -u root
After successfully login, type this command:
Now we are going to change the root password.
For MySQL 5.7.6, MariaDB 10.1.20 and newer version:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NEW_PASSWORD';
For MySQL 5.7.5, MariaDB 10.1.20 and older version:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('NEW_PASSWORD');
NEW_PASSWORD should be your new password.
Step 3 : Restart the Database Server
After performing clean-up operations, we should run this command to exit smoothly:
# MySQL sudo kill `cat /var/run/mysqld/mysqld.pid` #MariaDB sudo kill `/var/run/mariadb/mariadb.pid`
Now restart the database server:
# MySQL sudo systemctl start mysql #MariaDB sudo systemctl start mariadb
Step 4 : Test the Password
We have successfully changed the root password. Now we are going to check the password is changed or not. Run this command:
mysql -u root -p
After hitting this, you will be asked for password. Now enter the newly changed password and you should gain access to the database server.
Preview may take a few seconds to load.
Below you will find some common used markdown syntax. For a deeper dive in Markdown check out this Cheat Sheet
Bold & Italic
Bold **double asterisks**
Three back ticks and then enter your code blocks here.
# This is a Heading 1
## This is a Heading 2
### This is a Heading 3
> type a greater than sign and start typing your quote.
You can add links by adding text inside of  and the link inside of (), like so:
To add a numbered list you can simply start with a number and a ., like so:
1. The first item in my list
For an unordered list, you can add a dash -, like so:
- The start of my list
You can add images by selecting the image icon, which will upload and add an image to the editor, or you can manually add the image by adding an exclamation !, followed by the alt text inside of , and the image URL inside of (), like so:
To add a divider you can add three dashes or three asterisks:
--- or ***