Reset Mysql database root Password

To Reset any Mysql Database you need to perform following operations

  1. Stop the MySQL server
  2. Locate my.cnf and add following line to [mysqld] block
     skip-grant-tables = 1 
  3. Start mysql server and login using following command
     mysql 
  4. Change password for root user
     UPDATE mysql.user SET Password=PASSWORD('abc123') WHERE User='root';  

    or

     UPDATE mysql.user SET authentication_string=PASSWORD('q1w2e3r4') WHERE User='root';  

    then issue

     FLUSH PRIVILEGES; 
  5. Restart Mysql after removing skip-grant-tables variable from my.cnf

Note: skip-grant-tables enables anyone to connect without a password and with all privileges, and disables account-management statements such as ALTER USER and SET PASSWORD, Because this is insecure. if the server is started with the –skip-grant-tables option, it enables –skip-networking automatically to prevent remote connections.