mysql 访问_mysql设置对外访问

报错:Host is not allowed to connect to this MySQL server解决方法

先说说这个错误,其实就是我们的MySQL不允许远程登录,所以远程登录失败了,解决方法如下:

在装有MySQL的机器上登录MySQL mysql -u root -p密码

[root@localhost ~]# mysql -u root -p

Enter password:

执行use mysql;

mysql > use mysql;

执行update user set host = '%' where user = 'root';这一句执行完可能会报错,不用管它。

执行FLUSH PRIVILEGES;

全部命令

[root@localhost ~]#mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection idis 12Server version:8.0.11 MySQL Community Server -GPL

Copyright (c)2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracleis 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>use mysql;

Reading table informationforcompletion of table and column names

You can turn offthis feature to get a quicker startup with -A

Database changed

mysql> update user set host = '%' where user = 'root';

Query OK,1 row affected (0.06sec)

Rows matched:1 Changed: 1 Warnings: 0mysql>FLUSH PRIVILEGES;

Query OK,0 rows affected (0.00sec)

mysql>

经过上面4步,就可以解决这个问题了。

注: 第四步是刷新MySQL的权限相关表,一定不要忘了,我第一次的时候没有执行第四步,结果一直不成功,最后才找到这个原因。

如果以上还不能解决问题,可以尝试

报错:authentication plugin 'caching_sha2_password

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';

以上两步骤基本可以解决 mysql对外访问了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值