Yesterday Everything was working fine. Today when i start mysql its start giving me following error message
ERROR 1045 (28000): Access denied for user \'root\'
Stop the mysql service
Edit the my.ini
file or my.cnf
file
Find the [mysqld]
section in the ini file and add this line directly after the section [mysqld]
skip-grant-tables
Restart the mysql service.
Open the MySQL console
Now we are going to reset the password for the root user, of course this could be used to reset any users password.
Enter the following 2 commands at the mysql> command prompt, each with a semi colon at the end of a line, and press ENTER after each line to issue the command to mysql.
Pre MYSQL version 5.7
UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;
Post MYSQL version 5.7 the column name changed
UPDATE mysql.user SET authentication_string=PASSWORD('MyNewPass') WHERE User='root';
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES;
Note that the update may report that it has updated more than one row, that because there are actually 3 user accounts with the userid of 'root' each with a different domain i.e. 127.0.0.1, localhost and ::1
Now enter quit
at the mysql command prompt to exit mysql.
Stop the mysql service
Edit the my.ini file or my.cnf file
Find the {mysqld] section in the ini file and Remove the skip-grant-tables
parameter we added earlier.
DO NOT Leave this parameter in the ini file its a HUGH security hole.
Restart the mysql service.
You should now be able to login with phpmyadmin using the userid 'root' and the new password you have just set for that user.