IDEA连接mysql数据库错误
Connection to @localhost failed.
[08001] Could not create connection to database server. Attempted reconnect 3 times. Giving up.

产生原因
时区问题。mysql默认美国时区,在中国与之时区不对应
jdbc-connector版本
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.21</version>
</dependency>
解决方案
在URL处进行修改,改为UTC世界统一时区
jdbc:mysql://localhost:3306/test?serverTimezone=UTC

本文介绍了解决IDEA连接MySQL数据库时遇到的时区问题,详细解释了问题产生的原因,包括时区不匹配及jdbc-connector版本影响,并提供了解决方案,通过修改URL设置为UTC时区。
1562

被折叠的 条评论
为什么被折叠?



