配置 mysql 远程访问
主要原因,root 配置了 localhost
步骤
> 登录root用户,
> 进入mysql数据库,
> 修改root 的主机名为可以访问所有主机,
> 重新更新root的所有权限
> 刷新权限
use mysql;
mysql> select host, user from user;
+-------------+-------------------------+
| host | user |
+-------------+-------------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-------------+-------------------------+
4 rows in set (0.00 sec)
# 8.0之后的 mysql 不支持 授权的时候就进行用户创建,所以创建 之后才能授权;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;
ERROR 1410 (42000): You are not allowed to create a user with GRANT
这样使用
mysql> update user set host='%' where user='root' ;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> GRANT ALL ON *.* TO 'root'@'%';
ERROR 1410 (42000): You are not allowed to create a user with GRANT
mysql> grant all privileges on *.* to 'root'@'%' ;
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges ;
Query OK, 0 rows affected (0.00 sec)
mysql> select host, user from user;
+-----------+-------------------------+
| host | user |
+------------+------------------------+
| % | root |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
+------------+-------------------------+
4 rows in set (0.00 sec)
创建新用户 nacos
mysql> CREATE USER 'nacos'@'%' IDENTIFIED BY 'nacos-1234';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges ;
Query OK, 0 rows affected (0.00 sec)
mysql> select host, user from user;
+-------------+-------------------------+
| host | user |
+-------------+-------------------------+
| % | nacos |
| % | root |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
+-------------+-------------------------+
5 rows in set (0.00 sec)