最近博主在学习数据库方面的知识,使用druid连接mysql出现了问题,由于是在自己的电脑上测试,因此使用的是本机的ip,但是出现了几个错误,解决方案如下:
1.Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
解决方案:将连接的url从127.0.0.1改为localhost:
解决完第一个问题后又报了另一个错误:
2.java.sql.SQLException: Access denied for user ''@'localhost' (using password: YES)
解决方案:在url后设置serverTimezone=GMT或者Asia/Shanghai
druid.properties文件内容如下:
driverClassName=com.mysql.cj.jdbc.Driver url=jdbc:mysql://localhost:3306/test?serverTimezone=Asia/Shanghai username=root password=123456 initialSize=5 maxActive=10 maxWait=1814400
希望答案能够帮到你们。