mysql8.0.32设置root用户可以远程访问

未设置远程访问,会报如下的错

[root@cenots7 ~]# mysql -h192.168.30.20 -uroot -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'192.168.30.90' (using password: YES)
[root@cenots7 ~]# 

 

开启root用户的远程访问

复制代码
mysql> set global validate_password.policy=LOW;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password.length=6;
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE USER 'root'@'%' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.01 sec)

mysql> grant all privileges on *.* to 'root'@'%';
Query OK, 0 rows affected (0.01 sec)
复制代码

提示意思是不能用grant创建用户,mysql8.0以前的版本可以使用grant在授权的时候隐式的创建用户,8.0以后已经不支持,所以必须先创建用户,然后再授权,如上述命令

现在就可以了

复制代码
[root@cenots7 ~]# mysql -h192.168.30.20 -uroot -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'192.168.30.90' (using password: YES)
[root@cenots7 ~]# mysql -h192.168.30.20 -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2256376
Server version: 8.0.31 MySQL Community Server - GPL

Copyright (c) 2000, 2023, 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> 
复制代码

 

posted @   李小期  阅读(216)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示