IDEA连接MySQL失败-[08S01] Communications link failure

发布时间:2022-07-01 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了IDEA连接MySQL失败-[08S01] Communications link failure脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

IDEA连接MySQL失败-[08S01] Communications link failure

一、问题现状描述

使用IDEA启动maven项目,报错连接MySQL数据库失败,尝试用IDEA的database插件,连接本地MySQL库(Windows10本机搭建)

IDEA连接MySQL失败-[08S01] Communications link failure

报错结果如下:

[08S01] 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.

java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.

IDEA连接MySQL失败-[08S01] Communications link failure

使用Navicat等工具可以连接成功

IDEA连接MySQL失败-[08S01] Communications link failure

1. 使用命令窗口可以连接成功

2. 服务端已设置用户可以远程访问

IDEA连接MySQL失败-[08S01] Communications link failure

二、问题排查

MySQL 5.7除了配置服务端配置,还要配置my.cnf文件。

1)/etc//my.conf

2)E:PATSToolsmysql-5.7.34-winx64my.ini

即一般linux 上都放在 /etc/my.cnf ,window 上安装都是默认可能按照上面的路径还是没找到,Windows上可以登录到mysql中 使用 show variables like '%data%' 先找到data存放路径,一般my.ini 在 data文件的上一级。

2.1 Linux系统配置

 # my.cnf中有选项bind-address=127.0.0.1,是说mysql server监听的是本地发来的请求 #如果是任意主机都可以请求,则写为0.0.0.0,但是这样又不太安全。 # 监听某ip,指定此ip地址即可,但是要保证mysql的user中有允许此ip访问,否则不能对数据库操作 ​ bind-address=0.0.0.0

这样配置可实现远程访问,并且IDEA也可直接访问

2.2 Window系统配置

bind-address=127.0.0.1注释掉,默认就是bind-address=0.0.0.0

my.cnf中有选项bind-address=127.0.0.1,是说mysql server监听的是本地发来的请求,如果是任意主机都可以请求,则写为0.0.0.0,但是这样又不太安全。监听某ip,指定此ip地址即可,但是要保证mysql的user中有允许此ip访问,否则不能对数据库操作。那么是否可以在配置里只规定几个ip呢?

简单直接回答:不可能(详情参考

 [mysqld] # 设置3306端口 port=3306 # 设置mysql的安装目录 basedir=E:PATSToolsmysql-5.7.34-winx64mydata # 设置mysql数据库的数据的存放目录 datadir=E:PATSToolsmysql-5.7.34-winx64mydatadata ## 允许最大连接数 max_connections=1000 ## 允许连接失败的次数。 max_connect_errors=100 ## 服务端使用的字符集默认为utf8mb4 character-set-server=utf8mb4 ## 创建新表时将使用的默认存储引擎 default-storage-engine=INNODB ## 默认使用“mysql_native_password”插件认证 ##mysql_native_password #default_authentication_plugin=mysql_native_password ##sql_mode设置 ##查询 select @@sql_mode,去除ONLY_FULL_GROUP_BY sql_mode= STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION #注释掉允许任意远程连接 # 放开注释: #   bind-address=127.0.0.1              本地连接 #   bind-address=xxx.xxx.xxx.xxx        指定IP连接 bind-address=127.0.0.1 [mysql] ## 设置mysql客户端默认字符集 default-character-set=utf8mb4 [client] ## 设置mysql客户端连接服务端时默认使用的端口 port=3306 default-character-set=utf8mb4 

2.3 bind-address本地设置

bind-address设置为127.0.0.1本地连接后,IDEA就可以正常启动maven项目,database插件也可正常连接MySQL

IDEA连接MySQL失败-[08S01] Communications link failure


以上,请参考!

脚本宝典总结

以上是脚本宝典为你收集整理的IDEA连接MySQL失败-[08S01] Communications link failure全部内容,希望文章能够帮你解决IDEA连接MySQL失败-[08S01] Communications link failure所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:数据库