客户端连接不上linux上的mysql_Linux命令(十)之使用Windows客户端连接Linux系统中的MySQL时产生的错误已经解决...

若在windows使用工具连接MySQL是报如下两种错误:

错误1:

An error occurred while establishing the connection:

Long Message:

Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

Details:

Type: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException

SQL State: 08S01

错误2:

An error occurred while establishing the connection:

Long Message:

null, message from server: "Host '192.168.202.1' is not allowed to connect to this MySQL server"

Details:

Type: java.sql.SQLException

Error Code: 1130

SQL State: HY000

注:不使用工具的话连接,使用windows的cmd命令远程连接的MySQL的命令为:

mysql -h 远程主机的地址 -u 用户名 -p

如:mysql -h 192.168.202.132 -u root -p

1. 产生错误1的原因:被Linux的防火墙拦截了访问

2. 产生错误2的原因:没有权限访问Linux中的mysql

注:先解决错误1再解决错误2

错误1的解决方法:①在防火墙中直接开放3306的端口;②或者直接关闭防火墙(强烈不推荐)

错误2的解决方法:

1)在Linux上,登陆MySQL:

mysql -u root -p (用root用户登陆)

2)查看MySQL的已有用户及权限

use mysql;

select host, user, password from user;

从下图中可以看到,只能本地访问该mysql服务。

9ef6c203cb6f2495d4ab1d038f9ab98f.png

3)插入特定数据后,再次查看user表内容

insert into user(host,user,password) values('%','root','*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B');

4)为root@%授权,让其具有所有权限

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;

5)插入成功后,重启MySQL服务就可以了

service mysql restart

若有遇到其他问题,请留言

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值