本地mysql连接出错Could not create connection to database server.

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
	at com.mysql.jdbc.Util.getInstance(Util.java:387)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:917)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:896)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:885)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
	at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2330)
	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2083)

查了好久,终于发现是pom.xml中配置的mysql-connector-java是5.1.39,而我本地mysql版本是8.0.11,版本不对应,把这个版本号改成8.0.11就没问题了,注意mysql8的驱动名称是:com.mysql.cj.jdbc.Drive

我这个问题是这样解决的,碰到这种问题网上还有说是数据库连接数再开大一点、修改事务配置之类的,祝愿大家能找到自己正确的解决方法

参考:https://blog.csdn.net/zhouzhiwengang/article/details/81024967

你可能感兴趣的:(本地mysql连接出错Could not create connection to database server.)