Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the mysql login error & # 039 access denied for user & # 039 localhost login error

2025-06-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article will explain in detail how to solve the problem of mysql login error 'Access denied for user' root'@'localhost'. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

First of all, I do not know how suddenly mysql uses the command line, workbench can not log in, all prompt 'Access denied for user' root'@'localhost'.

The database has been unloaded and reinstalled several times. It seems that the data can't be cleaned up. The pit encountered in the process of solution is recorded and shared here.

Record the valid operation:

1. First, skip permission to log in to mysql and view the user table.

Stop the mysql service ~ $sudo service mysql stop

Start MySQL~$ sudo mysqld_safe-- skip-grant-tables & in safe mode

Note:

May prompt mysqld_safe Directory'/ var/run/mysqld' for UNIX socket file don't exist

Solution: (the author tries to find that sudo must be added)

Sudo mkdir-p / var/run/mysqldsudo chown mysql:mysql / var/run/mysqld

Execute the safe mode above again to start mysql ~ $sudo mysqld_safe-- skip-grant-tables &

This prompt shows mysqld_safe Staring mysqld deamon with database from / var/lib/mysql

You can log in this time without a password: enter mysql-u root and log in.

The sql statement queries the mysql.user table as follows:

Add pictures (later)

Others suggested the following, but did not try

Open & Edit / etc/my.cnf or / etc/mysql/my.cnf, depending on your distro.

Add skip-grant-tables under [mysqld]

2. It is found that the plugin of user is socket_plugin and changed to mysql_native_password.

Modify the plugin permission of root:

Update mysql.user set authentication_string=PASSWORD ('newPwd'), plugin='mysql_native_password' where user='root';flush privileges;quit

(note that the revision here must be correct, so as not to carelessly reduce the content of plugin by one letter and the following twists and turns.)

3. There are other users in the user table. Root cannot log in. It is OK to log in with other users. A query has been made to find a valid operation:

In the installation directory of mysql, there is usually a debain.cnf file in / etc/mysql, which contains user,password. Use this to log in, and the password is finally copied, and then you can modify the plugin of user table root, as above.

Restart the mysql service, sudo service mysql restart

Users can log in with root.

This is the end of the article on "how to solve the Access denied for user 'root'@'localhost' problem of mysql login errors". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report