Error message:
mysql> select * from emp group by gender;
ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'db01.emp.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
Analyze the reasons:
Enter and run:select @@global.sql_mode;
get:
+-----------------------------------------------------------------------------------------------------------------------+
| @@global.sql_mode |
+-----------------------------------------------------------------------------------------------------------------------+
| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION |
+-----------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
Cause of the error, because the default to open ONLY_FULL_GROUP_BY
this property, and the group by the way you want to perform conflict.
Solution:
Will ONLY_FULL_GROUP_BY
this property be removed:
Above to view the properties of these:
ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
So it will ONLY_FULL_GROUP_BY
be removed, leaving the others.
get:
STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
The reason according to the above to do, because your property and I could not exactly the same, so a direct copy my code is likely to be unsuccessful.
These then this piece of code into the following ' '
years
Performing downlink codes (if an error occurs, according to the above mentioned ' '
inside change oh):
set sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
Finally, you have to enter exit
or quit
exit at the mysql client, and then log back in again, this time setting to take effect.