解决Connection to Xxx@localhost failed.


解决:
Connection to jianshu@localhost failed. [08001] Could not create connection to database server. Attempted reconnect 3 times. Giving up.

原因

2019最新版本IDEA,Pycharm连接JDBC方式为Mysql6中的com.mysql.cj.jdbc.Driver,这个方法需要指定时区【serverTimezone】

driverClassName=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/test?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=false
username=root
password=

老版本使用为Mysql5中的com.mysql.jdbc.Driver,不需要指定时区

driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false
username=root
password=
没懂??? 看图

你用Mysql5来斩我Mysql6

解决方法

  1. 更新mysql,官网下载
    8.0+版本解决,我本地用的MySQL5.7懒得改了就不用这个办法了

  2. 设置连接Mysql方式为5.x版本
    Nice

问题

1.1 问题描述

最近把IDEA升级到2019版本发现数据库一直连接不上,一直提示时区错误【mysql时区问题解决方法】,解决完后发现数据库显示已连接但是无法查看数据库内容
扯蛋显示,没有数据库显示
网上找了资料才知道IJ大哥把2019版本的IDEA Pycharm连接方式都默认改为了com.mysql.cj.jdbc.Driver

1.2 报错截图

idea截图

解决

更改IDEA连接方式
再次Nice

搞定✔


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM