连接mysql

最近在学习springboot,刚刚学到了连接数据库这里。作为小白的我遇见一个奇怪的错误

1
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

配置信息

1
2
3
4
spring.datasource.url=jdbc:mysql://localhost:3306/test1?useSSL=true
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

原来是开启了ssl加密连接方式。但是又没有配置ssl加密,所以导致不能连接上数据库。
mysql高版本都推荐使用ssl的方式连接数据库。
配置方法

不过不需要使用ssl这种连接方式的话可以使用useSSL=false避免这个错误 ,或者使用verifyServerCertificate=false不使用证书配置

1
spring.datasource.url=jdbc:mysql://localhost:3306/test1?useSSL=true&verifyServerCertificate=false
文章作者: roMummy
文章链接: http://romummy.github.io/2018/07/12/连接mysql/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 roMummy