数据库MySQL8版本在使用过程中遇到以下错误问题:
SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'info.baidu' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by (Connection: mysql, SQL: SELECT created_at AS date, baidu AS baidu_num, sougou AS sougou_num, hao360 AS hao360, bing AS bing_num, baidu+hao360+sougou+bing AS sum_num FROM seo_info GROUP BY date order by date desc limit 10
这个错误发生在使用SQL查询时,表示SQL语法错误或访问违规。具体到这个错误代码SQLSTATE[42000]: Syntax error or access violation: 1055,表示在执行查询时,MySQL遇到了一个语法错误,或者是在尝试执行查询时违反了访问权限。 在这个特定的错误信息中,Expression #2 of SELECT指的是SELECT语句中的第二个表达式出现了问题。MySQL期望在某些情况下,例如在使用GROUP BY或ORDER BY子句时,所有非聚合函数的列都应该出现在同一个子句中。
解决方法:
打开my.cnf文件,本文一linux系统为例,文件位置位于etc/my.cnf下,在[mysqld]新增下面一行,即可解决。
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
文章评论(0)