How do I change the password of a MySQL / Mariadb user?

Category:

MariaDB MySQL security

If you have access to the server's console, you can change the password of the user of your choice via the mysql client in SSH.

If you have access to SSH, enter the following to access the mysql client:

:~$ sudo mysql
[sudo] password for youruser:

You will then see - after correctly entering your SSH user's password, the following console:

Welcome to the MariaDB monitor. Commands end with ; or φ.
Your MariaDB connection id is 3260
Server version: 10.5.19-MariaDB-0+deb11u2 Debian 11

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

Choose the appropriate database where you want to change the user, on mysql/mariadb installations this defaults to "mysql":

MariaDB [(none)]> use mysql;
Database changed

Then enter the new password via an SQL statement and hit enter:

MariaDB [mysql]> SET PASSWORD FOR 'mydbusername'@'localhost' = PASSWORD('mynewpassword');
Query OK, 0 rows affected (0.001 sec)

The above query will change the password for mydbusername to mynewpassword.
Please note, this is only for logging into the database on localhost.
If you want mydbusername to be able to log in from any host you must specify '%' instead of 'localhost'.

You can exit the mysql client with exit after the change:

MariaDB [(none)]> exit;

Related articles

Discover here how we’ve fixed a blocking error when upgrading ESXi 6.5 to 7.0 update 2 through vSphere Lifecycle Manager.

Kinamo maintains multiple VMware vSphere clusters, not only for our own infrastructure, but also for a variety of customers. As...

Read more

How to fix driver issues when upgrading VMware ESXi

Kinamo maintains multiple dedicated VMware vSphere clusters for our customers. One of the critical tasks in maintaining a healthy and...

Read more

Installing NVIDIA VGPU driver for ESXi via vCenter Lifecycle manager

As NVIDIA Solution Advisor, Kinamo maintains a VMware vSphere cluster for a VMware Horizon VDI deployment of one of our...

Read more

Need extra help?

Were not all your questions answered?
Don't worry, we will be happy to help you via a support request!

Kinamo

Select your language

All languages: