一、出现的问题
1、据我理解大概就是说表名不存在找不到的意思吧
2、连接本地数据库或局域网数据库时一切正常(同一个数据库)
3、报错信息,截了主要的一部分
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1f5e6d30]
org.springframework.jdbc.BadSqlGrammarException:
### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'schoolattendance.Snap_record' doesn't exist
### The error may exist in file [E:\pxc\StudentRecordStatisticsWeb\target\classes\core\dao\Snap_recordMapper.xml]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select id,photo_url,photo_url_face,similarity,match_guid,guid as stu_No, camera_ip,time,device_name,address,create_time,per_type,device_id,device_area from `Snap_record` WHERE match_guid = ? and time >= ? and time <= ? order by time limit ?,?
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'schoolattendance.Snap_record' doesn't exist
; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'schoolattendance.Snap_record' doesn't exist
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:234)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
二、我的开发环境
1、首先我是jdk1.8+mysql 5.5+spring-boot 2.0.5.RELEASE
2、我在做的项目用到了spring-boot + mybatis + ActiveMQ + elasticsearch
3、连接的数据库是在外网(mysql)
三、分析错误出现的原因
1、最开始想到的是因为连接外网数据库时配置没有配置好。
2、参考了:https://www.cnblogs.com/ieiang/p/6403818.html,经测试确实是因为表名中存在大写而导致报错。
四、解决方案
1、方法一:把表名改成全小写,问题解决。(存在一个大写字母都不行)
2、方法二:执行 vim /etc/my.cnf 在[mysqld]下加入一行:lower_case_table_names = 1即可(linux下的数据库),windows下配置叫my.ini应该是同理(windows下未测试过)
3、友情提示:linux下的mysql数据库要关闭防火墙,不然连接不上。