全是手贱惹得货!!!!com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
问题描述:
下午写接口的时候,想测试一下是否与数据库联通,于是便出现了一下的bug,大概意思就是自带的默认数据源异常。
2020-11-19 18:17:06.599 ERROR 10752 --- [nio-8081-exec-2] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
原因分析:
于是分析数据库配置:
urce.driver-class-name =com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/online_xleiclass?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=123456
#使⽤阿⾥巴巴druid数据源,默认使⽤⾃带的
#spring.datasource.type =com.alibaba.druid.pool.DruidDataSource
#开启控制台打印sql
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
# mybatis 下划线转驼峰配置,两者都可以
#mybatis.configuration.mapUnderscoreToCamelCase=true
mybatis.configuration.map-underscore-to-camel-case=true
#配置扫描
mybatis.mapper-locations=classpath:mapper/*.xml
#配置xml的结果别名
mybatis.type-aliases-package=com.shenlei.domain
经过再三检查发现也没有问题,密码时区都感觉没什么问题,后天看到网上有兄弟说可能是com.mysql.jdbc.Driver
是 mysql-connector-java 5中的,而在mysql-connector-java 6中已经过时,于是查看自己的mysql-connector-java版本,发现果然是6:
于是把com.mysql.jdbc.Driver
改为:com.mysql.cj.jdbc.Driver,再次启动,还是同样的错误。
于是便可排除配置文件的错误,再次检查报错日志,发现
2020-11-19 18:17:06.624 ERROR 10752 --- [nio-8081-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'performance_schema.session_variables' doesn't exist
### The error may exist in file [D:\IdeaWorkplace2\online_xleiclass\target\classes\mapper\VideoMapper.xml]
### The error may involve com.shenlei.mapper.VideoMapper.ListVideo
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'performance_schema.session_variables' doesn't exist] with root cause
尼玛,看到这心理一万个MMP,这个东西好熟悉,Table 'performance_schema.session_variables' doesn't exist
这不就是我今上午手贱删除的一个数据库里的一个默认的表,上午觉得它没什么用,就给删了。
原来:
performance_schema在mysql5.5以上就有自带
performance_schema(安装数据库时自带的)如果装数据库或者使用数据时不小心删除了,就会出现Table‘performance_schema.session_variables’ doesn’t exist的异常。
于是就想办法把他给恢复。
解决方案:
# mysql_upgrade -u root -p --force
此时重启mysql就可以了,performance_schema这个表就恢复了
此时再连接数据库就不会出错了。