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
Reset root MySQL/MariaDB password on Ubuntu 20.04
Reset root MySQL/MariaDB password on Ubuntu 20.04

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
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


SUBSCRIBE TO NEWSLETTER
Subscribe to Linux Career NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


  1. 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 &
    
  2. Confirm that the MySQL/MariaDB daemon is up and running:
    $ ps aux | grep mysqld
    
    Skip Grant tables on MySQL server
    Skip Grant tables on MySQL server


  3. 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
    
    Reset a root password on MySQL server
    Reset a root password on MySQL server
  4. Restart the MySQL/MariaDB server:
    $ sudo pkill mysqld
    $ sudo systemctl start mysql
    


  5. 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.'
    
    Login with a new password
    Login with a new password
FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in:



Comments and Discussions