[Solved] ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES) or (password: NO)

When I log in to Mysql and enter the password, I get this error

Error message 1:

or

Error message 2:

Solution 1 (simple)

This kind of error occurs, because many people have forgotten the password. You can use this command to view the mysql default password:

grep 'temporary password' /var/log/mysqld.log

example:

Use this command to find out that my mysql password is: s:*8jexp7OX_

When you use the mysql -u root -p command to log in to mysql, you can copy it to the password column.

Solution 2

1. Edit the directory

vim /var/log/mysqld.log

2. After entering, enter / first, then password -> press enter, as shown below:

3. Then it will help you automatically locate the line with the mysql password, copy the password behind root@localhost to log in to mysql.

Exit command: Type : , then exit -> and press enter, as follows As shown in the figure:

Finish. . .

The article knowledge points match the official knowledge files, and you can further learn related knowledge CS introductory skill tree Linux entry First acquaintance with Linux15717 people are learning the system