编程知识 cdmana.com

The problem of using localhost and 127.0.0.1 to connect to MySQL database under Linux

One 、 Problem description
1、 stay linux After installation mysql after , adopt mysqladmin The command sets the password of administrator authority ;

    mysqladmin -u root password ' password '

2、 adopt mysql -u root -p Enter the set password , Life and death hints

    ‘ERROR 1045 (28000): Access denied for user    'root'@'localhost' (using password: YES)’ 

3、 Post this error message to the browser to search , Then according to the online way to operate , Tried n Methods , It didn't work
4、 In the end, there's no way , I think I have the wrong permission configuration , Unload and reload the database , The problem remains
Two 、 Problem solving
1、 Try to connect to the database with the client , It's a wonderful discovery that can connect
2、 Reuse mysql -h 127.0.0.1 -u root -p Enter the password to connect , It's the same mistake
3、 And then the intranet of the server ip De link , Finally, I went in
image.png
4、 Then I started to find out why

(1) First look for user information , Find out localhost Of user No root   

image.png

(2) to update user Table settings localhost The user of is root
update mysql.user set user = 'root' where host = 'localhost';
(3) Again mysql -u root -p +  password , The problem is still 

image.png

(4) Go back to the user information table , Find out localhost and 127.0.1 There is no corresponding password 

image.png

(5) For users root Set the same password for the address of 
UPDATE mysql.user SET Password=PASSWORD(' password ') where USER='root';

image.png

(6) Refresh permission list , Use... Again mysql -u root -p +  The password can be used to connect to the database 

image.png
image.png

3、 ... and 、mysql Kind of localhost and 127.0.1 The difference between , Recommended documents

https://gohalo.me/post/mysql-localhost-vs-127.0.0.1-introduce.html

Four 、 summary

 It's not that difficult , Just myself linux and mysql Knowledge is not solid enough , It's just a big detour ; If you start to analyze user information , Maybe we can solve the problem faster 
 It's painful to have problems , The process of solving it is painful , It's fun to analyze and solve problems !!!

版权声明
本文为[Leisurely wind]所创,转载请带上原文链接,感谢

Scroll to Top