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

时间:2019-07-24 18:33:51   收藏:0   阅读:155

若在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

 

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

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

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

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

  具体操作步骤,请参考博客:https://www.cnblogs.com/sun-flower1314/p/11214237.html

错误2的解决方法:

  1)首先登陆Linux,再登陆MySQL:

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

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

    use mysql;

    select host, user, password from user;

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

  技术分享图片

   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

 

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

 

原文:https://www.cnblogs.com/sun-flower1314/p/11239430.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!