0


mysql报错:1044 -Access denied for user ‘root‘@‘%‘ to database

使用Navicat远程连接,Docker中的mysql5.7版本中新建数据库报错:

1044 -Access denied for user 'root'@'%' to database 

远程连接工具可以成功连接,docker中数据库容器,但是只会显示自动生成的数据库,其他的必要数据库无法显示出来:

报错是因为root没有权限的原因,找到一下两种解决办法:

1.修改权限

mysql> SELECT host,user,Grant_priv,Super_priv FROM mysql.user;
+-----------+---------------+------------+------------+
| host      | user          | Grant_priv | Super_priv |
+-----------+---------------+------------+------------+
| localhost | root          | Y          | Y          |
| localhost | mysql.session | N          | Y          |
| localhost | mysql.sys     | N          | N          |
| %         | root          | Y          | Y          |
| localhost | mysqladmin    | Y          | Y          |
+-----------+---------------+------------+------------+
5 rows in set (0.00 sec)

mysql> UPDATE mysql.user SET Grant_priv='Y', Super_priv='Y' WHERE User='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2  Changed: 0  Warnings: 0

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

查询用户表看root用户权限

SELECT host,user,Grant_priv,Super_priv FROM mysql.user;

修改权限,命令如下:

UPDATE mysql.user SET Grant_priv='Y', Super_priv='Y' WHERE User='root';
FLUSH PRIVILEGES;

2.赋权

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set host='%' where user='root';
ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

mysql赋权操作,总结命令如下:

use mysql;
update user set host='%' where user='root';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';

两个方法都可以试试,我遇到这个问题时把两个方法用了一遍,中间忘记重启容器了,所以不知道是哪个方法起到的作用,所以记得重启一下MySQL容器

命令:

重启docker容器

systemctl restart docker

重启MySQL容器

docker restart mysql
标签: 大数据 docker mysql

本文转载自: https://blog.csdn.net/qq_54928486/article/details/125666293
版权归原作者 小龙Hibernation 所有, 如有侵权,请联系我们删除。

“mysql报错:1044 -Access denied for user ‘root‘@‘%‘ to database”的评论:

还没有评论