我在mysql里面设置了一个root@'%' 远程连接是可以连接上的,但是在mysql数据库本机是连接不上的,即使加上-h 也是不行,老是提示
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)。难道非要grant all privileges on *.* to 'root'@'localhost' identified by 'root' with grant option,创建一个localhost吗,%表示任意的主机,为什么不包括 localhost?

解决方案 »

  1.   

    select  * from mysql.user 看一下内容。
      

  2.   

    怎么设置的root@‘%’
    %表示任意的主机,肯定包括 localhost
      

  3.   

    有些时候(有些版本)'%'不包括localhost,要单独对@'localhost'进行赋值.
      

  4.   

    运行命令 Grant all on db.* to 'user'@'localhost' identified by "pass" 看看。   当不加@选项时,效果与加@'%'是一样的,'%'从名义上包括任何主机,(%必须加上引号,不然与@放在一起可能不会被辨认出。)不过有些时候(有些版本)'%'不包括localhost,要单独对@'localhost'进行赋值。