# Stop mariadb
sudo systemctl stop mariadb
# start MariaDB as safe mode
sudo mysqld_safe --skip-grant-tables --skip-networking &
# log in as root
mysql -u root
# Reset
FLUSH PRIVILEGES;
# Change password
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
# Quit safe mode'ed MariaDB
sudo kill `/var/run/mariadb/mariadb.pid`
# Start MariaDB as if nothing happened
sudo systemctl start mariadb
# Login as root
mysql -u root -p