Have you or one of your MariaDB users forgotten the password to a MariaDB account? It's very easy to reset a MariaDB user password on Linux, and we'll show you the commands and step by step instructions below.
Resetting the MariaDB root password requires a different set of instructions, which we also cover below. Depending on which account you need to change the password for (a normal user or root), follow the appropriate section below.In this tutorial you will learn:
- How to change MariaDB user password
- How to change MariaDB root password
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the |
|Conventions|| # - requires given linux commands to be executed with root privileges either directly as a root user or by use of |
Change MariaDB User Password
Open a command line terminal on your machine and follow the steps below to change the password to a normal MariaDB user account (not root).
- Start by logging into MariaDB as the root user.
$ mariadb -u root -p
- Next, switch to the
MariaDB [(none)]> use mysql;
- Switch the user's password by using the following syntax (replace values where necessary).
MariaDB [mysql]> ALTER USER 'user'@'localhost' IDENTIFIED BY 'new_password';
- Lastly, flush privileges and exit MariaDB.
MariaDB [mysql]> FLUSH PRIVILEGES; MariaDB [mysql]> exit
That's all there is to it. Make sure the changes worked by trying to login from your shell with the new password.
$ mariadb -u username -p
Change MariaDB Root Password
The process for changing the root password in MariaDB is a bit more involved. The step by step instructions below will help you to change the password or reset it in case you've forgotten it.
- Let's start by stopping the currently running MariaDB database.
$ sudo systemctl stop mariadb
- Start the database process again, but this time with the
--skip-grant-tablesoption, which will allow us to connect to the database without needing a password. The
&just tells Linux to background the process. Alternatively, you could omit the ampersand and just open a new terminal window for the next few steps.
$ sudo mysqld_safe --skip-grant-tables --skip-networking &
- Login to MariaDB as root. You won't be asked for a password.
$ mariadb -u root
- Flush privileges and then change the root password using the following command. Replace our password example with whatever you'd like your password to be.
MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password_here'; MariaDB [(none)]> exit
- Gracefully terminate the current mysqld process, and then start your MariaDB server back up.
$ sudo pkill mysqld $ sudo systemctl start mariadb
- To verify everything works, try to login to MariaDB as root, while specifying the password you just set.
$ mariadb -u root -p
In this guide, we saw how to change/reset a user password in MariaDB. We also saw how to reset the root password, which involves taking the database offline and relaunching it with different permissions. If you happen to forget the password again, you'll know where to find this guide.