MySQL授权用户 'test'@'%',却在localhost中不能登录。
mysql -utest -h127.0.0.1 -p 或者mysql -utest -hlocalhost -p
报如下错误
ERROR 1045 (28000): Access denied for user 'test'@'localhost' (using password: YES)
查看mysql数据库中的user表数据如下:
mysql> select host ,user from user where user='test'; +-------------------------+---------------+ | host | user | +-------------------------+---------------+ | % | test | +-------------------------+---------------+ 8 rows in set (0.00 sec)
原来是因为%并不包括localhost。
解决方案:将需要将localhost加入到user表
grant all privileges on *.* to 'test'@'localhost' identified by 'test' with grant option;
flush privileges;