How to reset mysql or Mariadb root password ?
How to reset mysql or Mariadb root password ?
1. First you need to stop mysql or Mariadb server.
[email protected]:# service mariadb stop
[email protected]:~# service mysql stop
2. Start the MySQL/MariaDB server without loading the grant tables.
[email protected]:~# mysqld_safe --skip-grant-tables &
When the --skip-grant-tables option is used, anyone can connect to the database server without a password and with all privileges granted.
3. Log in to the Mysql shell
[email protected]:~# mysql -u root.
4. Set a new password.
At the mysql > prompt, reset the password. To do this, type the following command, replacing "new-password" with the new root password
UPDATE mysql.user SET Password=PASSWORD('new-password') WHERE User='root';
5. At the mysql> prompt, type the following commands:
FLUSH PRIVILEGES;
exit;
6. Stop the MySQL server using the following command. You will be prompted to enter the new MySQL root password before the MySQL server shuts down:
[email protected]:~# mysqladmin -u root -p shutdown
7 Start the mysql/mariadb server normally
[email protected]:~# service mariadb start