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.
2. Start the MySQL/MariaDB server without loading the 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 or MariaDB shell
4. Set a new password.
Type the following command, replacing "new-password" with the new root password
MariaDB [(none)]> UPDATE mysql.user SET Password=PASSWORD('new-password') WHERE User='root';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit;
5. 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:
6. Start the MySQL/MariaDB server normally
[email protected]:~# service mariadb start
7. Once started you can check the status of MariaDB service using service mariadb status command as shown below:
[email protected]:~#service mariadb status
8. Log in to MariaDB with New Password
Test the new reset MariaDB root password by logging in to the Server using mysql -u root -p command as shown below. Once you provide the root password it should allow you to log in just the way it is described below.
[[email protected] ~]# mysql -u root -p
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.