After installing the MariaDB database we need to change the password for the root user. If the password is not changed then anyone could log into your database do what they like to it.
We’ll do that now while we are in the client. First, we need to get into the MySQL Client by typing in the following at the console
sudo mysql
You should see the ‘mysql>’ prompt after the Welcome details. Follow the next steps to change the root password.
We’ll do that now while we are in the client. First, we need to get into the MySQL Client by typing in the following at the console
sudo mysql
You should see the ‘mysql>’ prompt after the Welcome details. Follow the next steps to change the root password.
- type the following at the prompt to see current users
SELECT user, host, password FROM mysql.user;
+------+-----------+----------+
| user | host | password |
+------+-----------+----------+
| root | localhost | |
+------+-----------+----------+
1 row in set (0.00 sec)
As you see above the root user does not have a password (assuming that you have not already changed the password for root)
- type the following to change the password for the root user
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password');
Query OK, 0 rows affected, 1 warning (0.00 sec)
- Now do the first step again to confirm that the password has been set
SELECT user, host, password FROM mysql.user;
+------+-----------+-------------------------------------------+
| user | host | password |
+------+-----------+-------------------------------------------+
| root | localhost | *0913BF2E2CE20CE21BFB1961AF124D4920458E5F |
+------+-----------+-------------------------------------------+
1 row in set (0.00 sec)
This time the password is not empty. Note that it’s also a ‘hash’ of the password you used
- Next, we need to tell MariaDB to clear any cached credentials. Type the following to clear/flush credentials
FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
- To quit the MySQL Client type the following and then press Enter
quit;