Reset the MySQL root Password

From Hashmysql
Jump to: navigation, search
      • In /etc/my.cnf under [mysqld] add a line:

init-file=/var/lib/mysql/init-file


      • In bash shell, create the file:

touch /var/lib/mysql/init-file chown mysql. /var/lib/mysql/init-file

      • Place the command in the file:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'somePassword2' REQUIRE NONE WITH GRANT OPTION;


      • Restart the service:

/etc/init.d/mysqld stop /etc/init.d/mysqld start


      • Verify your new password:

mysql -uroot -psomePassword2


      • Remove the init-file line from my.cnf so it does not reset password every reboot:
  1. init-file
      • Remove the file you created to prevent prying eyes:

/bin/rm /var/lib/mysql/init-file