未设置远程访问,会报如下的错
[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>