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

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
mkdir /var/run/mysqld
3. Grant MySQL permission to use the created directory.
chown mysql: /var/run/mysqld
mysqld_safe --skip-grant-tables --skip-networking &
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.
Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ ) shared "MySQL ERROR 1045 (28000): Access denied for user 'root'@'localhost' how to solve" will help you.
Welcome to share the link of this article:https://www.chenweiliang.com/cwl-30369.html
To unlock more hidden tricks🔑, welcome to join our Telegram channel!
If you like it, please share and like it! Your sharing and likes are our continuous motivation!