Fix MySQL error: SELECT list is not in GROUP BY clause and contains nonaggregated column incompatible with sql_mode=ONLY_FULL_GROUP_BY

There is a system variable ONLY_FULL_GROUP_BY in MySQL engine.
From MySQL v5.7.5: ONLY_FULL_GROUP_BY SQL mode is enabled by default.
Before v5.7.5: ONLY_FULL_GROUP_BY was not enabled by default.
If the ONLY_FULL_GROUP_BY SQL mode is enabled, MySQL rejects queries for which the SELECT list, HAVING condition, or ORDER BY list refer to non-aggregated columns that are neither named in the GROUP BY clause nor are functionally dependent on them.

You can check current sql_mode with:

show variables like "sql_mode";
To fix the above error use:
SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
And reconnect to database.