首先程序报错信息为:
ERROR 1055 (42000): Expression #7 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘monitor.device_camera.device_id’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible withsql_mode=only_full_group_by
报错原因是因为使用了group by聚合函数,在mysql8.0及以上版本中,如果在select后的列没有在group by 后面出现,默认这个sql是不合法的。
解决方法:
1、一劳永逸法:修改msyql配置文件my.cnf
在[mysqld] 下添加 sql_mode=‘NO_AUTO_VALUE_ON_ZERO,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,PIPES_AS_CONCAT,ANSI_Q UOTES’
重启mysql
service mysql restart
2、临时方法,但是在mysql重启之后失去作用
在Navicat中输入
1)
SELECT @@sql_mode;
该命令查询sql_mode的配置
set sql_mode =‘STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION’;
修改sql_mode配置
2)
SELECT @@GLOBAL.sql_mode;
SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,‘ONLY_FULL_GROUP_BY’,’’));