1. Start MySQL/MariaDB without the grant tables option. This will allow us to log in 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

  3. At this point, log in 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

  4. Restart the MySQL/MariaDB server:
    $ sudo pkill mysqld
    $ sudo systemctl start mysql


  5. At this point you should be able to log in to the MySQL/MariaDB server with the password as set in Step 3:
    $ mysql -u root --password='N3w_p@ssw0rD.'
Was this answer helpful? 0 Users Found This Useful (0 Votes)