MySQL允许root远程登录
MySQL默认用户登录是本地,也就是localhost
我的MySQL版本是:8.0.26
进入mysql:
进入mysql后使用mysql数据库:
查询现有用户的允许登录方式:
Text Only |
---|
| mysql> SELECT host,user FROM user;
|
可以看到root的host是localhost:
Text Only |
---|
| +-----------+------------------+
| host | user |
+-----------+------------------+
| localhost | root |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+------------------+
|
使用更新语句,使root用户能够以任何ip登录(也就是%
):
Text Only |
---|
| mysql> UPDATE user SET host = '%' WHERE user = 'root';
|
得到响应:
Text Only |
---|
| Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
|
再次查询:
Text Only |
---|
| mysql> SELECT host,user FROM user;
|
得到响应:
Text Only |
---|
| +-----------+------------------+
| host | user |
+-----------+------------------+
| % | root |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+------------------+
|
最后刷新权限:
至此,root用户可以远程登录MySQL了。