MariaDB / MySQL Root Forgot password

Have you lost your password list again? The login data of main users are quickly lost and are not saved on the system itself.
It is certainly easier here with databases that are used by Content Management Systems, here the password is stored in plain text in the respective configuration files. This is not the case for the main user of the database server.
Usually the user name is root. At Plesk installations the username "admin" is used. The password of a Plesk server can be easily retrieved from the .psa/shadow file. For example: with the command:

mysql -uadmin -p`cat /etc/psa/.psa.shadow

If you need to reset the password completely, simply follow these steps.

Exit the database server. E.g. under Centos7 with MariaDB with

systemctl stop mariadb.service

If you use another database server, this can also be done with

/etc/init.d/mysql stop

MariaDB / MySQL root Change password

Now we start the database server without restrictions and rights management, so that it can be administered without a password. To do this, we use the -skip-grant-tables option, which removes the restrictions, and -skip-networking, which prevents external access during setup.

mysqld_safe --skip-grant-tables --skip-networking &

Now you can easily change the MySQL password.

mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD("the_desired_password") where User='root';
mysql> flush privileges;
mysql> exit

Now the password is changed and the database server can be terminated.

mysqladmin shutdown

So that it can then be started normally.

systemctl start mariadb.service

Further information can of course also be found in the manufacturer's manual at https://mariadb.com.

Current articles