mysql将某数据库的全部权限赋给某用户,提示1044错误Access denied
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix'; ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'zabbix'
查看root用户有没有授权权限
mysql> select host,user,grant_priv,Super_priv from mysql.user; +-----------+----------+------------+------------+ | host | user | grant_priv | Super_priv | +-----------+----------+------------+------------+ | 127.0.0.1 | root | Y | Y | | localhost | root | N | Y | | 10.0.3.% | repluser | N | N | +-----------+----------+------------+------------+ 3 rows in set (0.00 sec)
可以看到localhost的grant_priv的值为N,也就是说root用户不能授权给其他用户,所以我们需要把这个值改为Y
mysql> update mysql.user set grant_priv='N' where host='localhost'; Query OK, 0 rows affected (0.00 sec) Rows matched: 1 Changed: 0 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
改完之后最好重启一下服务器(我没重启,所以还是报那个错,重启后就正常了)
mysql> select user,host,Grant_priv,super_priv from mysql.user; +----------+-----------+------------+------------+ | user | host | Grant_priv | super_priv | +----------+-----------+------------+------------+ | root | 127.0.0.1 | Y | Y | | root | localhost | Y | Y | | repluser | 10.0.3.% | N | N | +----------+-----------+------------+------------+ 3 rows in set (0.00 sec) mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix'; Query OK, 0 rows affected (0.00 sec) mysql>