[Solved] ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using passwor:yes) problem solution and steps

mysql encountered ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using passwor:yes) problem

Problem Description:
After downloading mysql, I want to set a password. After entering /usr/bin/mysqladmin -u root -p ‘123456’, the following error occurred:


ERROR 1045 (28000) solution:
Method 1: ERROR 1045 (28000) Password-free login to MySQL
Then enter the terminal again, type the mysql -u root -p command and press Enter. When you need to enter a password, press the enter key directly to log in to the database without a password, as shown in the figure:


enter:

mysql>UPDATE mysql.user SET Password=PASSWORD('new password')where USER='root' ;
Query OK, 3 rows affected (0.01 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

After exiting and restarting, you can log in to MySQL with the new password.