This is step by step if you lost your root password mariadb, just follow step bellow :

Log into your GNU/Linux system as the user used by MySQL (usually ‘mysql’) or root.

Stop MariaDB and start again with the grant tables disabled:

# mysqld_safe --skip-grant-tables --skip-networking

  mysqld_safe will shut down mysqld for you.
  With --skip-grant-tables, no password is needed to logon.
  This is unsafe, so until the password is reset MariaDB should not accept network connections (--skip-networking).

Logon with no password:

# mysql -u root

Set your new password.

   Exec these 2 SQL statements and exit the client:

   --change pwd
   MariaDB> UPDATE `mysql`.`user`
	SET `Password` = PASSWORD('new_password')
	WHERE `User` = 'root';
   --tell the server to read the grant tables

(replace ‘new_password’ with the new password)

Stop mysqld_safe and start mysqld:

# /etc/init.d/mysql stop
# /etc/init.d/mysql start

Logon to mysql with new-password was you set before

hope this article help fully


souurce :