Incompatible with sql_mode=only_full_group_by [Fix]

Updated on October 30, 2018

While migrating a client website from one WHM/cPanel to another WHM/cPanel, I got an SQL error “Incompatible with sql_mode=only_full_group_by“. Below is the complete error message.

SELECT list is not in GROUP BY clause and contains nonaggregated column 'dbname.p.picfile' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

Solution: MySQL 5.7.5+ has changed GROUP BY behavior to be SQL99 compliant (Older versions were not) and that was the reason for the error.

The workaround is to edit your MySQL configurations to remove ONLY_FULL_GROUP_BY option from sql_mode. This will change GROUP BY behavior back to its pre-MySQL 5.7.5 behavior.

Shared Hosting

If you are on a shared hosting, you will not be able to change the sql_mode at the environment level.

Remove ONLY_FULL_GROUP_BY in my.cnf file

If you have access to MySQL configuration file my.cnf, open the file:

# vim /etc/mysql/my.cnf

and add the below line to the end of the file:

[mysqld]  
 sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

Restart the MySQL service:

# systemctrl restart mysql
Disable ONLY_FULL_GROUP BY

This will disable the ONLY_FULL_GROUP_BY for ALL users of the system.

Remove ONLY_FULL_GROUP_BY in WHM/cPanel

If your domain is on a cPanel (Shared Hosting), then you need to contact your hosting provider to update the same.

If you have access to WHM, then access PHPMyAdmin under SQL Services from WHM as shown below:

whm phpmyadmin access

Click on Variables from the menu and search for SQL_MODE

SQl_MODE in phpmyadmin

Click on edit button and change remove ONLY_FULL_GROUP_BY. Once edited, click on  save.

change sql_mode in phpmyadmin

That’s it!

Was this article helpful?

Related Articles

Comments Leave a Comment

  1. its not working on my site. massage shows need super admin access

  2. if i do this option from whm as you mention is it affecting other websites ? is dangerous please advise

Leave a Comment