How to reset/change MariaDB root password?

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

… comes the message.

Server version: 10.1.35-MariaDB-1

So, you did not mess with your server. You are fairly certain others have not messed with it. So what could have happened? Well, count me in. I have all the security updates enabled. Only have auto-updated WP sites, secured MySQL, key-based SSH, all the fluff.

Yet, the password for root (only) broke. Probably an update.
Let’s fix it.

1. First option. Was ineffective for me.

sudo service mariadb stop
sudo mysqld_safe --skip-grant-tables --skip-networking &
mysql -u root
use mysql;
update user set password=PASSWORD("password") where User='root';
flush privileges;

2. Second option. Worked for me.

sudo mysql -u root
# Optional, check if you even have a root user
SELECT User,Host FROM mysql.user;
DROP USER 'root'@'localhost';
CREATE USER 'root'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;

I am not to held responsible if your computer/server blows up.
Replace “password” obviously in the commands.

Leave a Reply

Your email address will not be published. Required fields are marked *