解决:Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:

报错信息如下:

org.apache.ibatis.exceptions.PersistenceException:

Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server; consider upgrading MySQL client

The error may exist in com/lbl/dao/IPersonDao.xml

The error may involve com.lbl.dao.IPersonDao.findAll

The error occurred while executing a query

Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server; consider upgrading MySQL client

org.apache.ibatis.exceptions.PersistenceException:

Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server; consider upgrading MySQL client

The error may exist in com/lbl/dao/IPersonDao.xml

The error may involve com.lbl.dao.IPersonDao.findAll

The error occurred while executing a query

MySQL版本和驱动包不兼容的问题

于是我查看了自己的mysql版本

解决:Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:

再看了看自己pom.xml文件的mysql驱动版本

解决:Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:

再查看自己连接数据库时,连接的是哪一个版本的数据库

解决:Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:

这就找到了报错的原因了。

原因:

mysql驱动是5.0+版本的,而连接的数据库版本是8.0+版本的,所以连接不上。

解决办法:

1.改连接数据库与mysql驱动版本一致的5.0+版本

2.改mysql驱动为8.0+版本

这里要注意,如果将mysql驱动改为8.0+版本,则还要改驱动的类名,加cj字段

把驱动的类名改为:
driver="com.mysql.cj.jdbc.Driver";