07-27-2019, 09:03 AM
Hello!
A brief quide on how to reset the MariaDB MySQL root password if you forgot it or your previous password stopped working for some reason. You will need root or sudo access on your server to do the following steps.
That's it folks. This is how you reset passwords for MySQL root or actually also any other MySQL user from the command line.
BE CAREFUL WITH THE USE OF MYSQL IN SAFEMODE! It's basically like an open bank vault.
A brief quide on how to reset the MariaDB MySQL root password if you forgot it or your previous password stopped working for some reason. You will need root or sudo access on your server to do the following steps.
- Connect to your server via SSH or any other similar means of remote access for Linux servers.
- Login as root or a user that has administrative permission through the "sudo" application.
- Stop all MariaDB MySQL processes using the command below (outfitted for more recent Linux distributions using systemd!):
Code: (Select All)systemctl stop mariadb
Don't forget to use sudo infront of the command if you're not root!
- Now start MariaDB MySQL in safemode using the following command:
Code: (Select All)mysqld_safe --skip-grant-tables &
Don't forget to use sudo infront of the command if you're not root! The safemode will allow to login as root without a password as a mean of emergency access to the database.
After running this command it might seem like it's stuck. Simply press the ENTER key to continue in the command line.
- Start the MySQL command line tool and login as MySQL root:
Code: (Select All)mysql -u root
- Select the "mysql" database as that is where the user accounts and other server information is stored:
Code: (Select All)USE mysql;
- Flush privileges to avoid error messages about "insecure execution" of queries:
Code: (Select All)FLUSH PRIVILEGES;
- Use the command below to set a new password for the root user:
Code: (Select All)UPDATE USER SET PASSWORD=PASSWORD("newpasswordhere") WHERE USER='root';
Make sure to replace "newpasswordhere" with the new password for the MySQL root user.
- Flush privileges again to reload permissions of the users:
Code: (Select All)FLUSH PRIVILEGES;
- Logout and close the MySQL command line:
Code: (Select All)exit
- Stop the MariaDB safemode:
Code: (Select All)killall mysqld
- Start all normal MariaDB processes:
Code: (Select All)systemctl start mariadb
That's it folks. This is how you reset passwords for MySQL root or actually also any other MySQL user from the command line.
BE CAREFUL WITH THE USE OF MYSQL IN SAFEMODE! It's basically like an open bank vault.