今天拿到了一个SQL, 在windows上的数据库运行是没有什么问题的. 但是移动Mac电脑上, 就出现了这个问题:
SELECT list is not in GROUP BY clause and contains nonaggregated column 'db_blog2.t2.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
这是这条SQL
SELECT t2.id AS id, t2.typeName AS typeName, COUNT(t1.id) AS blogCount FROM t_blog t1 RIGHT JOIN t_blogType t2 ON t1.typeId=t2.id GROUP BY t2.typeName order by t2.orderNo
已经确认是没有任何问题, 但是为什么还是会报出上面的这个问题呢?原来是需要修改my.cnf (我是Mac)在/etc/my.cnf 中 加上一个,NO_AUTO_CREATE_USER
. 记住, 先停止mysql服务然后再修改配置.然后再重启mysql服务.