您的位置:首页 > 数据库 > MySQL

mysql可以远程连接,但是不能本地连接

2015-09-28 16:41 603 查看
mysql空用户(user列为空)带来的影响

mysql> create user 'setest'@'%' identified by 'sepwd';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> select user, password, host from mysql.user where user="setest";
+--------+-------------------------------------------+------+
| user | password | host |
+--------+-------------------------------------------+------+
| setest | *D916076B3441EFE82B5D01B2ECF5E15DED34B0B3 | % |
+--------+-------------------------------------------+------+
1 row in set (0.00 sec)

mysql> quit
Bye
[root@oracle-test ~]# mysql -usetest -p
Enter password:
ERROR 1045 (28000): Access denied for user 'setest'@'localhost' (using password: YES)
用工具可以远程连接。

解决办法:
mysql> select user,host,password from mysql.user;
+--------+----------------+-------------------------------------------+
| user | host | password |
+--------+----------------+-------------------------------------------+
| root | localhost | 64f6539969715ad7 |
| root | term001 | |
| root | 127.0.0.1 | |
| | localhost | |
| | term001 | |
| setest | % | *D916076B3441EFE82B5D01B2ECF5E15DED34B0B3 |
+--------+----------------+-------------------------------------------+
9 rows in set (0.00 sec)

这里有两个空用户,将这两个空用户删除,mysql> drop user term001; mysql> drop user localhost;然后本地连接就可以了,具体原因可以参照原作者答案。

源地址:http://blog.csdn.net/zbszhangbosen/article/details/7434154

百度白天没有结果,换成Google后,马上找到答案了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: