In this guide we will reset the lost root MySQL/MariaDB password on Ubuntu 20.04 Focal Fossa. This can be achieved by disabling the root authentication and longing in without the password.
In this tutorial you will learn:
- How to reset root administrator password on MySQL 8 or higher
- How to reset root administrator password on MariaDB 10.3 or higher
- How to disable root authentication and login without password
Software Requirements and Conventions Used
Category | Requirements, Conventions or Software Version Used |
---|---|
System | Installed Ubuntu 20.04 or upgraded Ubuntu 20.04 Focal Fossa |
Software | MySQL 8.0, MariaDB 10.3 or higher |
Other | Privileged access to your Linux system as root or via the sudo command. |
Conventions |
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux commands to be executed as a regular non-privileged user |
Resetting root MySQL/MariaDB password on Ubuntu 20.04 step by step instructions
- Start MySQL/MariaDB without grant tables option.This will allow us to login to MySQL/MariaDB as a root user without a password:
$ sudo systemctl stop mysql $ sudo mkdir -p /var/run/mysqld $ sudo chown mysql:mysql /var/run/mysqld $ sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
- Confirm that the MySQL/MariaDB daemon is up and running:
$ ps aux | grep mysqld
- At this point, login to MySQL/MariaDB should not require any password:
$ mysql -u root
Execute the following SQL commands to reset your administrator password to
N3w_p@ssw0rD.
:> FLUSH PRIVILEGES; > USE mysql; > ALTER USER 'root'@'localhost' IDENTIFIED BY 'N3w_p@ssw0rD.'; > quit
- Restart the MySQL/MariaDB server:
$ sudo pkill mysqld $ sudo systemctl start mysql
-
At this point you should be able to login to the MySQL/MariaDB server with the password as set in the
Step 3 :$ mysql -u root --password='N3w_p@ssw0rD.'