Reset Your MariaDB or MySQL Root Password
Today we’re going to learn how to reset the root password of MySQL or MariDB. Let’s get started:
Table of Contents
- Stop Database Server
- Restart Database Server Without Permission
- Change Root Password
- Normally Restart Database Server
Stop Database Server
First, we need to shutdown our database server using this command:
# MariaDB
sudo systemctl stop mariadb
# MySQL
sudo systemctl stop mysql
Restart Database Server Without Permission
It will allow you to access the database command line with root privileges without providing a password:
sudo mysqld_safe --skip-grant-tables --skip-networking &
Now you’re able to login to database server without providing password:
mysql -u root
Change Root Password
Now let’s change root password:
MariaDB 10.1.20 and newer as well as MySQL 5.7.6 and newer:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
# if you face any issue, use this command:
UPDATE mysql.user SET authentication_string = PASSWORD('new_password') WHERE User = 'root' AND Host = 'localhost'
MariaDB 10.1.19 and newer as well as MySQL 5.7.5 and newer:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password');
Don’t forget to replace new_password
with your password.
Reload the grant tables using this command:
FLUSH PRIVILEGES;
Normally Restart Database Server
Run this command to restart the database server normally:
# MariaDB
sudo kill `/var/run/mariadb/mariadb.pid`
# MySQL
sudo kill `cat /var/run/mysqld/mysqld.pid`
After that restart database service:
# MariaDB
sudo systemctl start mariadb
# MySQL
sudo systemctl start mysql
Now you can login to databaser server using the new password:
mysql -u root -p
That’s all. Thank you. ?
Comment
Preview may take a few seconds to load.
Markdown Basics
Below you will find some common used markdown syntax. For a deeper dive in Markdown check out this Cheat Sheet
Bold & Italic
Italics *asterisks*
Bold **double asterisks**
Code
Inline Code
`backtick`Code Block```
Three back ticks and then enter your code blocks here.
```
Headers
# This is a Heading 1
## This is a Heading 2
### This is a Heading 3
Quotes
> type a greater than sign and start typing your quote.
Links
You can add links by adding text inside of [] and the link inside of (), like so:
Lists
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
Images
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:
Dividers
To add a divider you can add three dashes or three asterisks:
--- or ***

Comments (0)