How to solve MySQL ERROR 1045 (28000): Access denied for user 'root'@'localhost'

when you try to use MySQL database, you may encounter the following error message:

How to solve MySQL ERROR 1045 (28000): Access denied for user 'root'@'localhost'

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

How to solveMySQL ERROR 1045 (28000): Access denied for user 'root'@'localhost'?

1. Stop your server first

service mysql stop
2. Create a MySQL service directory.
mkdir /var/run/mysqld

3. Grant MySQL permission to use the created directory.

chown mysql: /var/run/mysqld
4. Start MySQL without permission and network check.
mysqld_safe --skip-grant-tables --skip-networking &
5. Log in to your server without any password.
mysql -u root mysql

or:

mysql -u root mysql

In the mysql client, tell the server to reload the grant tables so the account management statements work:

mysql> FLUSH PRIVILEGES;

then modify'root'@'localhost'account password.Replace password with the password you want to use.To change the password for the root account with a different hostname portion, modify the instructions to use that hostname.

MySQL 5.7.6 and later:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

MySQL 5.7.5 and earlier:

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');

or directly on the users table:

UPDATE mysql.user SET password=PASSWORD('mynewpassword') WHERE user='root';

For XAMPP

Stop the MySQL service,Open a command window and switch to the XAMPP MySQL directory:

> cd \xampp\mysql\bin\

To run the service without security (note that you are running mysqld, not mysql):

> mysqld.exe --skip-grant-tables

The MySQL service will be running in this window, so open another command window and change to the XAMPP MySQL directory:

> cd \xampp\mysql\bin\

Run the MySQL client:

> mysql

Update password:

mysql> UPDATE mysql.user SET password=PASSWORD('mynewpassword') WHERE user='root';

Quit MySQL:

mysql> \q

Use the task manager to cancel the mysqld.exe that is still running, and restart the MySQL service.

Comment

Your email address will not be published. Required fields * Callout

Scroll to Top