ERROR 1142 (42000): GRANT command denied to user ** 或 ERROR 1045 (28000): Access denied for user '**'@'localhost' (using password: YES)


★ 两个错误信息:都可能是权限不够的原因,当然第二个问题也有可能是密码输错了。


一、ERROR 1142 (42000): GRANT command denied to user **

错误产生背景:

在cmd控制台,选择某个用户shan,进入mysql服务:
输入命令:grant all on mysqldemo.t_student to shan@localhost;
结果报错:ERROR 1142 (42000): SELECT, GRANT command denied to user 'shan'@'localhost' for table 't_student'


然后输入命令:`grant all on mysqldemo.t_student to shan@localhost identitied by '密码' with grant option;`

结果报错:ERROR 1142 (42000): GRANT command denied to user 'shan'@'localhost' for table 't_student'

解决:在cmd控制台,选择用户root进入即可。


二、 ERROR 1045 (28000): Access denied for user '**'@'localhost' (using password: YES)

1、考虑是不是密码输错了---实在密码想不起来,那就重装一下mysql,mysql是没有找回密码的服务。
2、权限不够



总结:在cmd进入mysql进行一些权限分配时候,要注意用root用户进入哈~

看到错误信息“denied--不能” 可能是权限不够。

原文地址:https://www.cnblogs.com/shan333/p/15841026.html