目录
1.修改权限
2.赋权
使用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容器文章来源:https://www.toymoban.com/news/detail-519827.html
systemctl restart docker
重启MySQL容器 文章来源地址https://www.toymoban.com/news/detail-519827.html
docker restart mysql
到了这里,关于mysql报错:1044 -Access denied for user ‘root‘@‘%‘ to database的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!