springboot启动连接mysql报错Could not create connection to database server. Attempted reconnect 3 times. Gi

1.错误场景:错误提示如下

Could not create connection to database server. Attempted reconnect 3 times. Giving up.

2.分析原因

这个报错是连不上mysql,这里不考虑mysql权限限制不让远程访问的情况,剩下的百分之八十是设置mysql数据库连接加的参数不对。

3.解决方法

设置mysql连接参数如下,直接拷贝下面所有参数,来解决问题:

jdbc:mysql://127.0.0.1:3306/base?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2B8&useSSL=false&allowPublicKeyRetrieval=true&autoReconnect=true&failOverReadOnly=false

这里不设置ssl=true,以及serverTimezone需要确定设置了。

总结:这个参数都设置的一样后,可以解决出现的百分之八十错误情况,剩下的可能是mysql驱动版本和mysql版本不一致,mysql设置的账号访问权限不对等,这里不做讨论。

猜你喜欢

转载自blog.csdn.net/Mint6/article/details/107293567