Solution: MySQL error: 1045 - Access denied for user 'root'@'localhost'(using password YES)

I. Introduction

This year, I am crazy about open source. As long as I see a good open source project, I will go into research desperately. During May 1st, I found a good open source project about crowdfunding, but unfortunately, this project was written in PHP. , I haven't learned PHP, so naturally I have no clue about this open source project, but I decided to get into PHP for this project, so something happened...

It's too late to say it, it takes 2 hours to get started with PHP, and 2 hours to get started with ThinkPHP. Since I've been studying Java, I can get into the pit without much effort. Through understanding, the necessary environment for PHP development is PHP, Apache, MySQL and a good IDE. IDE is still easy to find. I chose PhpStorm from JetBrains, and the other environment is WampServer, which integrates all functions. Prepare to build database and table, open Navicat, the error starts...

2. Error description


MySQL 报错:1045- Access denied for user 'root'@'localhost'(using password YES)


As shown below:


3. Reasons for errors

After installing WampServer, an artifact that integrates the PHP development environment, the MySQL web page management software phpMyAdmin makes the root user permissions of the database change. It can also be said that the passwords are confused due to inconsistent passwords. understand), because the default password after phpMyAdmin installation is complete is empty.

Fourth, error resolution

The data error problem can be solved by directly recharging the password.

First of all, stop the running of the data, I believe everyone can do this, you can stop directly from the management service program, or you can directly enter the command net stop mysql in the cmd command window to stop.

Then enter the MySQL installation path, find and open the my.ini file, find the [mysqld] field, and add the following statement below this field:

skip_grant_tables

Then restart the database. I believe everyone can do this. You can open it directly in the management service program, or you can directly enter the command net start mysql in the cmd command window to open it, and then execute the command in the command window to reset the password. :

update user set password='root' where user='root'

Of course, I directly reset the password to root. Anyway, this password can be customized by everyone, but remember the password.

Finally, stop the database running again, return to the my.ini file mentioned above, remove the skip_grant_tables field and save it, and restart the database again to successfully resolve the MySQL error.

5. The problem continues

In the fourth part, I perfectly solved the error of the command window starting to enter the data, and then when I re-entered Navicat to open the locally established connection, I continued to report the same error, that is to say, the error was not resolved. I am very puzzled. Why can the command line operate the database smoothly without reporting an error, but when entering the Navicat client, an error is reported?

After tossing for a long time, I found that the connection established in Navicat is irreversible after resetting the password due to disordered root permissions.

After tossing for a long time, I found that the solution is also very simple. Either delete the connection and re-create a connection. Of course, after deleting the connection, the database that has been established will not be established, or reinstall Navicat. As for which one to choose, I have tried it all. , you can successfully solve this error reported by Navicat.

Sixth, the problem comes again

When the local error was solved perfectly, I opened the phpMyAdmin web page and reported a similar but different error to the previous one. The error is as follows:

1045- Access denied for user 'root'@'localhost'(using password NO)

When I also set the password in the local phpMyAdmin configuration file to the password of the MySQL database, the same error continued to be reported after opening it, and it continued to report errors, and after tossing for a long time, I finally found a solution on StackOverFlow: directly clear browsing The browser's cookie cache can solve this problem. That is to say, there is nothing wrong with my local configuration, and the reason why the webpage continues to report the error is that the browser has cached the login password of phpMyAdmin into the cookie when the error was reported before.

Well, all problems are solved perfectly, hereby recorded.

After solving this problem, we understand that if we encounter some errors and think carefully, instead of immersing ourselves in errors and studying them, we may be able to solve the problem in half an hour, instead of tossing for a day and a half.

Scan the QR code and follow the WeChat public account to learn more

------------------------------------

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325223706&siteId=291194637