How to reset mysql root password on linux system

If you forgot your mysql root password, not able to login to your mysql database. Don’t worry this is the simplest way I could find to reset mysql root user password.

  • Stop mysqldshell> /etc/init.d/mysql stop
  • Edit /etc/init.d/mysql file to add –skip-grant-tables option.Search for mysqld_safe text in this file, you might see this text being copied into some variable like SAFE_MYSQLD. Find out the place where they are starting the mysql server by using mysqld_safe or $SAFE_MYSQLD, you will have to add –skip-grant-tables option with that command.
  • Start mysqld with modified /etc/init.d/mysql file

shell> /etc/init.d/mysql start

  • Connect to the mysql server with this command, mysql wont prompt you for any password.

shell> mysql

  • Run the following mysql commands in the mysql client. Replace the password with the new root password that you want to set.mysql> UPDATE mysql.user SET Password=PASSWORD('NewRootPassword')WHERE User='root';
  • Don’t forget to remove –skip-grant-tables option from your /etc/init.d/mysql file and restart the mysql again. Now it will start asking you password for login.

You should now be able to connect to MySQL as root using the new password.

Leave a Reply

Your email address will not be published. Required fields are marked *