How to Reset MariaDB Root Password on CentOS 7. Today i logged in into my testing server (server for testing and learning, not my production server) because i want to test some server configuration. And because i am long time not login to this server, i am forgot my MariaDB password *lol. So, today i will show you how to reset MariaDB or MySQL database password.
If you have same problem as me (forgot mysql password), don’t worry, you can reset it if you have root or sudo access to your server.
First, you need to stop MariaDB process with this command
sudo service mariadb stop
Then run the service with safe mode command
sudo mysqld_safe --skip-grant-tables &
Now, you can login to your MariaDB without password
mysql -u root -p
Then, you can reset the password MariaDB password with this following command
use mysql; update user SET PASSWORD=PASSWORD("password") WHERE USER='root'; flush privileges; exit
Obviously you need to replace “password” with strong password.
After exit from MariaDB client, you need to kill all database process.
pkill -f 'mysql'
Then, restart MariaDB
sudo service mariadb restart
Now, you can login with your new password
[root@linuxsec ~]# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.60-MariaDB MariaDB Server 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)]>
That’s it. Hope this solution will help to fix your problem.