Mysql设置远程访问登录-is not allowed to connect to this mysql server

2021-03-26 11:44 阅读:1962
  • mysql -u root -p   登录到mysql中。
lingyun@lingyun-CN15S:~$ mysql -uroot -p
Enter password: 
  • 切换到mysql数据库下
mysql> use mysql;
  • 查询user表账号host访问地址
mysql> select host from user where user='root';
+-----------+
| host      |
+-----------+
| localhost |
+-----------+

当前root帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入MySQL后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%",也可以固定访问IP

这里查询的root账号,也可查询其他账号

  • 修改host值
mysql> update user set host = '%' where user ='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
  • 最后刷新配置
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

一定要执行这一句  flush privileges;

  • 再次查询确认
mysql> select host from user where user='root';
+------+
| host |
+------+
| %    |
+------+
1 row in set (0.00 sec)

其他账号修改地址方式同理,只需要将root改为相应的账号即可

{{commentTotal}} 条评论

{{item.nickname}}
{{item.create_date}}
{{item.content}}
- 上拉或点击加载更多 -
- 加载中 -
- 没有更多了 -
- 本文链接 -