原因:
- 原来的Root账号在(服务器)本地使用有权限登陆,远程的连接无法无权限访问。(之前可以正常连接操作)
- 远程登录权限突然是关闭的,也不知道怎么回事,估计目的是保护MySQL的安全吧,避免别人恶意的远程登录你的MySQL
解决:
- 执行SQL修改root的密码
mysql> grant all privileges on . to "root"@"%" identified by "xxxxx";
- 结果又报错了
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by xxxxx
- 查了下资料,应该是我的mysql版本过高,不能这种执行,只能分布式执行
mysql> SELECT @@VERSION;
+-----------+
+-----------+
| 8.0.27 |
+-----------+
1 row in set (0.00 sec)
- 分布式执行:(重新新建一个test用户,不用root用户)
mysql> create user 'test'@'%' identified by 'password';
Query OK, 0 rows affected (0.03 sec)
mysql> grant all privileges on *.* to 'test'@'%' with grant option;
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
- 重新远程连接成功!