mysql不能使用localhost登录

                        解决mysql不能使用localhost or 127.0.0.1登录                                  

参考:http://soft.chinabyte.com/database/409/12669909.shtml

因为root账户初始的时候有3条记录,包含root对应localhost,hostname,127.0.0.1三条账户数据,我们可以update host为其他两项中一项为localhost即可。


1.查询mysql.user表中的用户信息:

mysql> select host,user,password from mysql.user;
+---------------+------------------+-------------------------------------------+
| host          | user             | password                                  |
+---------------+------------------+-------------------------------------------+
| localhost     | root             | *DBF26618170E90D83FE55E6BB40FFAF894A58215 |
| 10-10-244-184 | root             |                                           |
| 127.0.0.1     | root             |                                           |
| ::1           | root             |                                           |
| localhost     |                  |                                           |
| 10-10-244-184 |                  |                                           |
| %             | user_game_server | *37A84E9F0D8C7E4B858676FAC681E036C7B55CBC |
| %             | user_game_select | *04AF85B5140B961767C4B6605D379F4A5F04D94D |
| %             | db_backup        | *0E6D97610A7A31752267BB2D6BE8AE85923A165E |
| %             | user_record      | *CE015679C3B849A7AD5797084D8593824C023A1A |
| %             | record_select    | *38CF7F37D19F2E199904430E889623D94175AA0C |
| %             | root             | *DBF26618170E90D83FE55E6BB40FFAF894A58215 |
+---------------+------------------+-------------------------------------------+

2.解决方法,删除这两个用户:

delete from mysql.user where host='localhost' and user=' ';

delete from mysql.user where host='10-10-244-184' and user=' ';

flush privileges;

原文地址:https://www.cnblogs.com/tangshengwei/p/5099979.html