报错:
mysql> GRANT ALL ON maxwell.* TO 'maxwell'@'%';
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'maxwell'
原因:
出现这个问题的原因是 root@'localhost’后面没有 WITH GRANT OPTION选项,可以使用命令进行查看
show grants for root@'localhost'
mysql> show grants for root@'localhost';
+--------------------------------------------------------------+
| Grants for root@localhost |
+--------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
+--------------------------------------------------------------+
2 rows in set (0.00 sec)
解决:
- 远程登录或使用Navicate登录
mysql -h192.168.3.35 -uroot -p123456
- 登录后,再给本地root localhost赋权限
GRANT ALL PRIVILEGES ON *.* TO root@'localhost' IDENTIFIED BY '123456' with grant option ;
- 验证是否生效:
mysql> show grants for root@'localhost';
+---------------------------------------------------------------------+
| Grants for root@localhost |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------+
2 rows in set (0.00 sec)
最后退出MySQL,重进,就可以了
mysql> exit;
Bye
[root@hadoop-3 maxwell]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 24
Server version: 5.7.35-log MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> GRANT ALL ON maxwell.* TO 'maxwell'@'%';
Query OK, 0 rows affected (0.05 sec)